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

Commit 37dca155 authored by Kenny Root's avatar Kenny Root
Browse files

KeySets: better rejection for badly-formed manifest

During testing, I typed in a <publicKey> tag incorrectly and it
clobbered the previously defined key entry since it still parsed the
subsequent <keyset> tag defining an alias.

This gives more information in the log when running into such parsing
errors.

Change-Id: Id3c8e85530b1a5e39f4a2cb6ea8bd5521cb6918f
parent 47e36c3c
Loading
Loading
Loading
Loading
+17 −0
Original line number Original line Diff line number Diff line
@@ -1554,10 +1554,15 @@ public class PackageParser {


        int type;
        int type;
        PublicKey currentKey = null;
        PublicKey currentKey = null;
        int currentKeyDepth = -1;
        Map<PublicKey, Set<String>> definedKeySets = new HashMap<PublicKey, Set<String>>();
        Map<PublicKey, Set<String>> definedKeySets = new HashMap<PublicKey, Set<String>>();
        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
            if (type == XmlPullParser.END_TAG) {
            if (type == XmlPullParser.END_TAG) {
                if (parser.getDepth() == currentKeyDepth) {
                    currentKey = null;
                    currentKeyDepth = -1;
                }
                continue;
                continue;
            }
            }
            String tagname = parser.getName();
            String tagname = parser.getName();
@@ -1567,9 +1572,21 @@ public class PackageParser {
                final String encodedKey = sa.getNonResourceString(
                final String encodedKey = sa.getNonResourceString(
                    com.android.internal.R.styleable.PublicKey_value);
                    com.android.internal.R.styleable.PublicKey_value);
                currentKey = parsePublicKey(encodedKey);
                currentKey = parsePublicKey(encodedKey);
                if (currentKey == null) {
                    Slog.w(TAG, "No valid key in 'publicKey' tag at "
                            + parser.getPositionDescription());
                    sa.recycle();
                    continue;
                }
                currentKeyDepth = parser.getDepth();
                definedKeySets.put(currentKey, new HashSet<String>());
                definedKeySets.put(currentKey, new HashSet<String>());
                sa.recycle();
                sa.recycle();
            } else if (tagname.equals("keyset")) {
            } else if (tagname.equals("keyset")) {
                if (currentKey == null) {
                    Slog.i(TAG, "'keyset' not in 'publicKey' tag at "
                            + parser.getPositionDescription());
                    continue;
                }
                final TypedArray sa = res.obtainAttributes(attrs,
                final TypedArray sa = res.obtainAttributes(attrs,
                        com.android.internal.R.styleable.KeySet);
                        com.android.internal.R.styleable.KeySet);
                final String name = sa.getNonResourceString(
                final String name = sa.getNonResourceString(