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

Commit 2e513c5b 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" into qt-qpr1-dev

parents 73582b6d 215d4321
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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(
+13 −0
Original line number Diff line number Diff line
@@ -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) { }
    }

    /**