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

Commit 423e746a authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Return real error strings from installd.

Now that we've moved installd to Binder, we can return nice detailed
error strings explaining why a call failed.  This is particularly
valuable when we record the error message into the PackageManager
persistent log, because up until now those errors were limited to
an unhelpful "installd returned -1" message.

Also perform uniform enforcement of all incoming package name and
UUID arguments.

Test: builds, boots, apps install/uninstall fine
Bug: 13758960, 30944031
Change-Id: Ic1f65ce8c10b1329e01d6a49d72cafa879c4d8bc
parent fce768d0
Loading
Loading
Loading
Loading
+271 −164

File changed.

Preview size limit exceeded, changes collapsed.

+10 −9
Original line number Original line Diff line number Diff line
@@ -53,7 +53,7 @@ namespace installd {
 * Check that given string is valid filename, and that it attempts no
 * Check that given string is valid filename, and that it attempts no
 * parent or child directory traversal.
 * parent or child directory traversal.
 */
 */
static bool is_valid_filename(const std::string& name) {
bool is_valid_filename(const std::string& name) {
    if (name.empty() || (name == ".") || (name == "..")
    if (name.empty() || (name == ".") || (name == "..")
            || (name.find('/') != std::string::npos)) {
            || (name.find('/') != std::string::npos)) {
        return false;
        return false;
@@ -64,7 +64,7 @@ static bool is_valid_filename(const std::string& name) {


static void check_package_name(const char* package_name) {
static void check_package_name(const char* package_name) {
    CHECK(is_valid_filename(package_name));
    CHECK(is_valid_filename(package_name));
    CHECK(is_valid_package_name(package_name) == 0);
    CHECK(is_valid_package_name(package_name));
}
}


/**
/**
@@ -135,7 +135,7 @@ std::string create_data_user_de_package_path(const char* volume_uuid,


int create_pkg_path(char path[PKG_PATH_MAX], const char *pkgname,
int create_pkg_path(char path[PKG_PATH_MAX], const char *pkgname,
        const char *postfix, userid_t userid) {
        const char *postfix, userid_t userid) {
    if (is_valid_package_name(pkgname) != 0) {
    if (!is_valid_package_name(pkgname)) {
        path[0] = '\0';
        path[0] = '\0';
        return -1;
        return -1;
    }
    }
@@ -266,12 +266,13 @@ int create_move_path(char path[PKG_PATH_MAX],
 * Checks whether the package name is valid. Returns -1 on error and
 * Checks whether the package name is valid. Returns -1 on error and
 * 0 on success.
 * 0 on success.
 */
 */
int is_valid_package_name(const char* pkgname) {
bool is_valid_package_name(const std::string& packageName) {
    const char* pkgname = packageName.c_str();
    const char *x = pkgname;
    const char *x = pkgname;
    int alpha = -1;
    int alpha = -1;


    if (strlen(pkgname) > PKG_NAME_MAX) {
    if (strlen(pkgname) > PKG_NAME_MAX) {
        return -1;
        return false;
    }
    }


    while (*x) {
    while (*x) {
@@ -281,7 +282,7 @@ int is_valid_package_name(const char* pkgname) {
            if ((x == pkgname) || (x[1] == '.') || (x[1] == 0)) {
            if ((x == pkgname) || (x[1] == '.') || (x[1] == 0)) {
                    /* periods must not be first, last, or doubled */
                    /* periods must not be first, last, or doubled */
                ALOGE("invalid package name '%s'\n", pkgname);
                ALOGE("invalid package name '%s'\n", pkgname);
                return -1;
                return false;
            }
            }
        } else if (*x == '-') {
        } else if (*x == '-') {
            /* Suffix -X is fine to let versioning of packages.
            /* Suffix -X is fine to let versioning of packages.
@@ -290,7 +291,7 @@ int is_valid_package_name(const char* pkgname) {
        } else {
        } else {
                /* anything not A-Z, a-z, 0-9, _, or . is invalid */
                /* anything not A-Z, a-z, 0-9, _, or . is invalid */
            ALOGE("invalid package name '%s'\n", pkgname);
            ALOGE("invalid package name '%s'\n", pkgname);
            return -1;
            return false;
        }
        }


        x++;
        x++;
@@ -302,13 +303,13 @@ int is_valid_package_name(const char* pkgname) {
        while (*x) {
        while (*x) {
            if (!isalnum(*x)) {
            if (!isalnum(*x)) {
                ALOGE("invalid package name '%s' should include only numbers after -\n", pkgname);
                ALOGE("invalid package name '%s' should include only numbers after -\n", pkgname);
                return -1;
                return false;
            }
            }
            x++;
            x++;
        }
        }
    }
    }


    return 0;
    return true;
}
}


static int _delete_dir_contents(DIR *d,
static int _delete_dir_contents(DIR *d,
+2 −1
Original line number Original line Diff line number Diff line
@@ -102,7 +102,8 @@ int create_move_path(char path[PKG_PATH_MAX],
                     const char* leaf,
                     const char* leaf,
                     userid_t userid);
                     userid_t userid);


int is_valid_package_name(const char* pkgname);
bool is_valid_filename(const std::string& name);
bool is_valid_package_name(const std::string& packageName);


int delete_dir_contents(const std::string& pathname, bool ignore_if_missing = false);
int delete_dir_contents(const std::string& pathname, bool ignore_if_missing = false);
int delete_dir_contents_and_dir(const std::string& pathname, bool ignore_if_missing = false);
int delete_dir_contents_and_dir(const std::string& pathname, bool ignore_if_missing = false);