Merge "DO NOT MERGE: Add size check on PPS#policy" into rvc-dev

This commit is contained in:
Nate(Qiang) Jiang
2023-04-14 19:43:49 +00:00
committed by Android (Google) Code Review

View File

@@ -16,6 +16,9 @@
package android.net.wifi.hotspot2.pps;
import static android.net.wifi.hotspot2.PasspointConfiguration.MAX_NUMBER_OF_ENTRIES;
import static android.net.wifi.hotspot2.PasspointConfiguration.MAX_STRING_LENGTH;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
@@ -269,11 +272,19 @@ public final class Policy implements Parcelable {
*/
public boolean validate() {
if (TextUtils.isEmpty(mFqdn)) {
Log.d(TAG, "Missing FQDN");
Log.e(TAG, "Missing FQDN");
return false;
}
if (mFqdn.getBytes(StandardCharsets.UTF_8).length > MAX_STRING_LENGTH) {
Log.e(TAG, "FQDN is too long");
return false;
}
if (TextUtils.isEmpty(mCountries)) {
Log.d(TAG, "Missing countries");
Log.e(TAG, "Missing countries");
return false;
}
if (mCountries.getBytes(StandardCharsets.UTF_8).length > MAX_STRING_LENGTH) {
Log.e(TAG, "country is too long");
return false;
}
return true;
@@ -449,7 +460,7 @@ public final class Policy implements Parcelable {
}
for (String ssid : mExcludedSsidList) {
if (ssid.getBytes(StandardCharsets.UTF_8).length > MAX_SSID_BYTES) {
Log.d(TAG, "Invalid SSID: " + ssid);
Log.e(TAG, "Invalid SSID: " + ssid);
return false;
}
}
@@ -457,15 +468,24 @@ public final class Policy implements Parcelable {
// Validate required protocol to port map.
if (mRequiredProtoPortMap != null) {
for (Map.Entry<Integer, String> entry : mRequiredProtoPortMap.entrySet()) {
int protocol = entry.getKey();
if (protocol < 0 || protocol > 255) {
Log.e(TAG, "Invalid IP protocol: " + protocol);
return false;
}
String portNumber = entry.getValue();
if (portNumber.getBytes(StandardCharsets.UTF_8).length > MAX_PORT_STRING_BYTES) {
Log.d(TAG, "PortNumber string bytes exceeded the max: " + portNumber);
Log.e(TAG, "PortNumber string bytes exceeded the max: " + portNumber);
return false;
}
}
}
// Validate preferred roaming partner list.
if (mPreferredRoamingPartnerList != null) {
if (mPreferredRoamingPartnerList.size() > MAX_NUMBER_OF_ENTRIES) {
Log.e(TAG, "Number of the Preferred Roaming Partner exceed the limit");
return false;
}
for (RoamingPartner partner : mPreferredRoamingPartnerList) {
if (!partner.validate()) {
return false;