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

Commit 444fc531 authored by Rhed Jao's avatar Rhed Jao
Browse files

Fix system crash while installing a package

Catch the illegal argument exception if the package declared
a malformed certificate digest of the required library.

Bug: 258811771
Test: atest android.os.cts.StaticSharedLibsHostTests
Change-Id: Ice3afaca7f73cd14e040cb9c77308575bb03869b
parent 383a0536
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -2233,6 +2233,15 @@ public abstract class PackageManager {
     */
    public static final int INSTALL_FAILED_PRE_APPROVAL_NOT_AVAILABLE = -129;

    /**
     * Installation return code: this is passed in the {@link PackageInstaller#EXTRA_LEGACY_STATUS}
     * if the new package declares bad certificate digest for a shared library in the package
     * manifest.
     *
     * @hide
     */
    public static final int INSTALL_FAILED_SHARED_LIBRARY_BAD_CERTIFICATE_DIGEST = -130;

    /** @hide */
    @IntDef(flag = true, prefix = { "DELETE_" }, value = {
            DELETE_KEEP_DATA,
@@ -9681,6 +9690,8 @@ public abstract class PackageManager {
            case INSTALL_FAILED_WRONG_INSTALLED_VERSION: return "INSTALL_FAILED_WRONG_INSTALLED_VERSION";
            case INSTALL_FAILED_PROCESS_NOT_DEFINED: return "INSTALL_FAILED_PROCESS_NOT_DEFINED";
            case INSTALL_FAILED_SESSION_INVALID: return "INSTALL_FAILED_SESSION_INVALID";
            case INSTALL_FAILED_SHARED_LIBRARY_BAD_CERTIFICATE_DIGEST:
                return "INSTALL_FAILED_SHARED_LIBRARY_BAD_CERTIFICATE_DIGEST";
            default: return Integer.toString(status);
        }
    }
+12 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.pm;

import static android.content.pm.PackageManager.INSTALL_FAILED_MISSING_SHARED_LIBRARY;
import static android.content.pm.PackageManager.INSTALL_FAILED_SHARED_LIBRARY_BAD_CERTIFICATE_DIGEST;

import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME;
import static com.android.server.pm.PackageManagerService.SCAN_BOOTING;
@@ -1035,8 +1036,17 @@ public final class SharedLibrariesImpl implements SharedLibrariesRead, Watchable
                    } else {
                        // lib signing cert could have rotated beyond the one expected, check to see
                        // if the new one has been blessed by the old
                        byte[] digestBytes = HexEncoding.decode(
                        final byte[] digestBytes;
                        try {
                            digestBytes = HexEncoding.decode(
                                    expectedCertDigests[0], false /* allowSingleChar */);
                        } catch (IllegalArgumentException e) {
                            throw new PackageManagerException(
                                    INSTALL_FAILED_SHARED_LIBRARY_BAD_CERTIFICATE_DIGEST,
                                    "Package " + packageName + " declares bad certificate digest "
                                            + "for " + libraryType + " library " + libName
                                            + "; failing!");
                        }
                        if (!libPkg.hasSha256Certificate(digestBytes)) {
                            throw new PackageManagerException(INSTALL_FAILED_MISSING_SHARED_LIBRARY,
                                    "Package " + packageName + " requires differently signed "