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
diff --git a/cmds/installd/utils.cpp b/cmds/installd/utils.cpp
index 674f760..4a38fa6 100644
--- a/cmds/installd/utils.cpp
+++ b/cmds/installd/utils.cpp
@@ -53,7 +53,7 @@
* Check that given string is valid filename, and that it attempts no
* 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 == "..")
|| (name.find('/') != std::string::npos)) {
return false;
@@ -64,7 +64,7 @@
static void check_package_name(const char* 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 @@
int create_pkg_path(char path[PKG_PATH_MAX], const char *pkgname,
const char *postfix, userid_t userid) {
- if (is_valid_package_name(pkgname) != 0) {
+ if (!is_valid_package_name(pkgname)) {
path[0] = '\0';
return -1;
}
@@ -266,12 +266,13 @@
* Checks whether the package name is valid. Returns -1 on error and
* 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;
int alpha = -1;
if (strlen(pkgname) > PKG_NAME_MAX) {
- return -1;
+ return false;
}
while (*x) {
@@ -281,7 +282,7 @@
if ((x == pkgname) || (x[1] == '.') || (x[1] == 0)) {
/* periods must not be first, last, or doubled */
ALOGE("invalid package name '%s'\n", pkgname);
- return -1;
+ return false;
}
} else if (*x == '-') {
/* Suffix -X is fine to let versioning of packages.
@@ -290,7 +291,7 @@
} else {
/* anything not A-Z, a-z, 0-9, _, or . is invalid */
ALOGE("invalid package name '%s'\n", pkgname);
- return -1;
+ return false;
}
x++;
@@ -302,13 +303,13 @@
while (*x) {
if (!isalnum(*x)) {
ALOGE("invalid package name '%s' should include only numbers after -\n", pkgname);
- return -1;
+ return false;
}
x++;
}
}
- return 0;
+ return true;
}
static int _delete_dir_contents(DIR *d,