From e41bc3155588c2fdc23b512a959e20e896da5180 Mon Sep 17 00:00:00 2001 From: Yi-wei Zhao Date: Tue, 23 Oct 2012 21:09:56 +0800 Subject: [PATCH] Fix dirfd crash issue in property service In "init: harden property service" patch, dirfd() is invoked without checking whether opendir() return successfully. It may fail if load_persistent_properties() is invoked before userdata partition is mounted; then dirfd(NULL) will make init crash. This may happen if "is_charger" is true. Change-Id: I216fb743a3c9fa050f92fcb31b62e766346d84bb Signed-off-by: Yi-wei Zhao --- init/property_service.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/init/property_service.c b/init/property_service.c index 2c1b4a1fc..31bc55ad7 100644 --- a/init/property_service.c +++ b/init/property_service.c @@ -510,13 +510,14 @@ static void load_properties_from_file(const char *fn) static void load_persistent_properties() { DIR* dir = opendir(PERSISTENT_PROPERTY_DIR); - int dir_fd = dirfd(dir); + int dir_fd; struct dirent* entry; char value[PROP_VALUE_MAX]; int fd, length; struct stat sb; if (dir) { + dir_fd = dirfd(dir); while ((entry = readdir(dir)) != NULL) { if (strncmp("persist.", entry->d_name, strlen("persist."))) continue;