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.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.regex.PatternSyntaxException;
|
import java.util.regex.PatternSyntaxException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -228,6 +229,10 @@ public class WifiP2pConfig implements Parcelable {
|
|||||||
|
|
||||||
private static final MacAddress MAC_ANY_ADDRESS =
|
private static final MacAddress MAC_ANY_ADDRESS =
|
||||||
MacAddress.fromString("02:00:00:00:00:00");
|
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 MacAddress mDeviceAddress = MAC_ANY_ADDRESS;
|
||||||
private String mNetworkName = "";
|
private String mNetworkName = "";
|
||||||
@@ -279,6 +284,10 @@ public class WifiP2pConfig implements Parcelable {
|
|||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"network name must be non-empty.");
|
"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 {
|
try {
|
||||||
if (!networkName.matches("^DIRECT-[a-zA-Z0-9]{2}.*")) {
|
if (!networkName.matches("^DIRECT-[a-zA-Z0-9]{2}.*")) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
|
|||||||
@@ -53,6 +53,13 @@ public class WifiP2pConfigTest {
|
|||||||
fail("Unexpected IllegalArgumentException");
|
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.
|
// less than 9 characters.
|
||||||
try {
|
try {
|
||||||
b.setNetworkName("DIRECT-z");
|
b.setNetworkName("DIRECT-z");
|
||||||
@@ -77,6 +84,12 @@ public class WifiP2pConfigTest {
|
|||||||
b.setNetworkName("direct-a?");
|
b.setNetworkName("direct-a?");
|
||||||
fail("expected IllegalArgumentException");
|
fail("expected IllegalArgumentException");
|
||||||
} catch (IllegalArgumentException e) { }
|
} catch (IllegalArgumentException e) { }
|
||||||
|
|
||||||
|
// over maximum bytes
|
||||||
|
try {
|
||||||
|
b.setNetworkName("DIRECT-abcdefghijklmnopqrstuvwxyz");
|
||||||
|
fail("expected IllegalArgumentException");
|
||||||
|
} catch (IllegalArgumentException e) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user