From 7130fb345dd5473fae538dfe1e1db64499d87fad Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Wed, 5 Apr 2017 12:15:49 -0700 Subject: [PATCH] libcutils: fs_config: target_out_path assumed /system Strip off /system/ and add appropriate config directory. Test: manual build successfully interprets all etc/fs_config_* files. Bug: 36071012 Change-Id: I2563248e91cea10fef3cc2f9e954e4782fdfce4f --- libcutils/fs_config.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/libcutils/fs_config.c b/libcutils/fs_config.c index daa9ff545..b26827c03 100644 --- a/libcutils/fs_config.c +++ b/libcutils/fs_config.c @@ -232,16 +232,20 @@ 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 guaranty it ends with '/system' - * we need this below skip_len logic */ + * system partition but as we cannot guarantee it ends with '/system' + * or a trailing slash or not, we need to strip them off. */ char* name = NULL; int target_out_path_len = strlen(target_out_path); - int skip_len = strlen("/system"); - if (target_out_path[target_out_path_len] == '/') { - skip_len++; + while ((target_out_path_len > 0) && + (target_out_path[target_out_path_len - strlen("/")] == '/')) { + --target_out_path_len; } - if (asprintf(&name, "%s%s", target_out_path, conf[which][dir] + skip_len) != -1) { + 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) { fd = TEMP_FAILURE_RETRY(open(name, O_RDONLY | O_BINARY)); free(name); }