Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 731fe661 authored by Jimmy Chen's avatar Jimmy Chen Committed by Android (Google) Code Review
Browse files

Merge "p2p: check the length of the network name bytes"

parents 385df92c a0900344
Loading
Loading
Loading
Loading
+9 −0
Original line number Original line Diff line number Diff line
@@ -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;


/**
/**
@@ -244,6 +245,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 = "";
@@ -295,6 +300,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(
+13 −0
Original line number Original line Diff line number Diff line
@@ -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) { }
    }
    }


    /**
    /**