From 29e0c8f1a9e5cd2be224be872b7f64d403846d62 Mon Sep 17 00:00:00 2001 From: Thierry Strudel Date: Fri, 7 Apr 2017 00:33:16 +0000 Subject: [PATCH] Revert "libcutils: fs_config: target_out_path assumed /system" This reverts commit 7130fb345dd5473fae538dfe1e1db64499d87fad. Bug: 36816191 Change-Id: I7d604d510865b1fa15781ffb4ad8b3e77ac44395 --- libcutils/fs_config.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/libcutils/fs_config.c b/libcutils/fs_config.c index b26827c03..daa9ff545 100644 --- a/libcutils/fs_config.c +++ b/libcutils/fs_config.c @@ -232,20 +232,16 @@ static int fs_config_open(int dir, int which, const char* target_out_path) { if (target_out_path && *target_out_path) { /* target_out_path is the path to the directory holding content of - * system partition but as we cannot guarantee it ends with '/system' - * or a trailing slash or not, we need to strip them off. */ + * system partition but as we cannot guaranty it ends with '/system' + * we need this below skip_len logic */ char* name = NULL; int target_out_path_len = strlen(target_out_path); + int skip_len = strlen("/system"); - while ((target_out_path_len > 0) && - (target_out_path[target_out_path_len - strlen("/")] == '/')) { - --target_out_path_len; + if (target_out_path[target_out_path_len] == '/') { + skip_len++; } - if ((target_out_path_len >= (int)strlen("/system")) && - !strcmp(target_out_path + target_out_path_len - strlen("/system"), "/system")) { - target_out_path_len -= strlen("/system"); - } - if (asprintf(&name, "%.*s%s", target_out_path_len, target_out_path, conf[which][dir]) != -1) { + if (asprintf(&name, "%s%s", target_out_path, conf[which][dir] + skip_len) != -1) { fd = TEMP_FAILURE_RETRY(open(name, O_RDONLY | O_BINARY)); free(name); }