Merge "p2p: check the length of the network name bytes" into qt-qpr1-dev
This commit is contained in:
@@ -28,6 +28,7 @@ import android.text.TextUtils;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
/**
|
||||
@@ -228,6 +229,10 @@ public class WifiP2pConfig implements Parcelable {
|
||||
|
||||
private static final MacAddress MAC_ANY_ADDRESS =
|
||||
MacAddress.fromString("02:00:00:00:00:00");
|
||||
/**
|
||||
* Maximum number of bytes allowed for a SSID.
|
||||
*/
|
||||
private static final int MAX_SSID_BYTES = 32;
|
||||
|
||||
private MacAddress mDeviceAddress = MAC_ANY_ADDRESS;
|
||||
private String mNetworkName = "";
|
||||
@@ -279,6 +284,10 @@ public class WifiP2pConfig implements Parcelable {
|
||||
throw new IllegalArgumentException(
|
||||
"network name must be non-empty.");
|
||||
}
|
||||
if (networkName.getBytes(StandardCharsets.UTF_8).length > MAX_SSID_BYTES) {
|
||||
throw new IllegalArgumentException(
|
||||
"network name exceeds " + MAX_SSID_BYTES + " bytes.");
|
||||
}
|
||||
try {
|
||||
if (!networkName.matches("^DIRECT-[a-zA-Z0-9]{2}.*")) {
|
||||
throw new IllegalArgumentException(
|
||||
|
||||
@@ -53,6 +53,13 @@ public class WifiP2pConfigTest {
|
||||
fail("Unexpected IllegalArgumentException");
|
||||
}
|
||||
|
||||
// sunny case with maximum bytes for the network name
|
||||
try {
|
||||
b.setNetworkName("DIRECT-abcdefghijklmnopqrstuvwxy");
|
||||
} catch (IllegalArgumentException e) {
|
||||
fail("Unexpected IllegalArgumentException");
|
||||
}
|
||||
|
||||
// less than 9 characters.
|
||||
try {
|
||||
b.setNetworkName("DIRECT-z");
|
||||
@@ -77,6 +84,12 @@ public class WifiP2pConfigTest {
|
||||
b.setNetworkName("direct-a?");
|
||||
fail("expected IllegalArgumentException");
|
||||
} catch (IllegalArgumentException e) { }
|
||||
|
||||
// over maximum bytes
|
||||
try {
|
||||
b.setNetworkName("DIRECT-abcdefghijklmnopqrstuvwxyz");
|
||||
fail("expected IllegalArgumentException");
|
||||
} catch (IllegalArgumentException e) { }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user