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

Commit cd727291 authored by William Loh's avatar William Loh Committed by Android (Google) Code Review
Browse files

Merge "Limit class name checks to bad characters" into main

parents 12905e49 c4ef7eec
Loading
Loading
Loading
Loading
+6 −24
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@ public class Element {
    public static final int MAX_ATTR_LEN_PATH = 4000;
    public static final int MAX_ATTR_LEN_DATA_VALUE = 4000;

    private static final String BAD_COMPONENT_NAME_CHARS = ";,[](){}:?-%^*|/\\";

    private static final String TAG = "PackageParsing";
    protected static final String TAG_ACTION = "action";
    protected static final String TAG_ACTIVITY = "activity";
@@ -790,34 +792,14 @@ public class Element {
    }

    void validateComponentName(CharSequence name) {
        int i = 0;
        if (name.charAt(0) == '.') {
            i = 1;
        }
        boolean isStart = true;
        for (; i < name.length(); i++) {
            if (name.charAt(i) == '.') {
                if (isStart) {
                    break;
                }
                isStart = true;
            } else {
                if (isStart) {
                    if (Character.isJavaIdentifierStart(name.charAt(i))) {
                        isStart = false;
                    } else {
                        break;
                    }
                } else if (!Character.isJavaIdentifierPart(name.charAt(i))) {
                    break;
                }
            }
        }
        if ((i < name.length()) || (name.charAt(name.length() - 1) == '.')) {
        for (int i = 0; i < name.length(); i++) {
            if (BAD_COMPONENT_NAME_CHARS.indexOf(name.charAt(i)) >= 0) {
                Slog.e(TAG, name + " is not a valid Java class name");
                throw new SecurityException(name + " is not a valid Java class name");
            }
        }
    }

    void validateStrAttr(String attrName, String attrValue) {
        if (attrValue != null && attrValue.length() > getAttrStrMaxLen(attrName)) {
+20 −2
Original line number Diff line number Diff line
@@ -518,8 +518,26 @@ class AndroidPackageParsingValidationTest {
            }
        }

        val failNames = arrayOf("com.android.TestClass:", "-TestClass", "TestClass.", ".", "..")
        for (name in failNames) {
        val badNames = arrayOf(
            ";",
            ",",
            "[",
            "]",
            "(",
            ")",
            "{",
            "}",
            ":",
            "?",
            "-",
            "%",
            "^",
            "*",
            "|",
            "/",
            "\\"
        )
        for (name in badNames) {
            val xml = "<$tag $attr=\"$name\" />"
            pullParser.setInput(ByteArrayInputStream(xml.toByteArray()), null)
            val validator = Validator()