installd: Avoid potential use of null 'src'.
In create_cache_path, we have code checking whether 'src' is null,
implying it's possibile it could be null here. To be safe, we move
our strlen call until after this check.
Change-Id: I6a67cdad8ebf8bdce1562ce5f0cbf98b084807ef
diff --git a/cmds/installd/installd.cpp b/cmds/installd/installd.cpp
index 7ca7527..38290cc 100644
--- a/cmds/installd/installd.cpp
+++ b/cmds/installd/installd.cpp
@@ -128,13 +128,13 @@
bool create_cache_path(char path[PKG_PATH_MAX],
const char *src,
const char *instruction_set) {
- size_t srclen = strlen(src);
-
- /* demand that we are an absolute path */
- if ((src == 0) || (src[0] != '/') || strstr(src,"..")) {
+ /* demand that we are an absolute path */
+ if ((src == nullptr) || (src[0] != '/') || strstr(src,"..")) {
return false;
}
+ size_t srclen = strlen(src);
+
if (srclen > PKG_PATH_MAX) { // XXX: PKG_NAME_MAX?
return false;
}