diff options
author | Scott Wood <scottwood@freescale.com> | 2014-04-07 23:49:35 (GMT) |
---|---|---|
committer | Scott Wood <scottwood@freescale.com> | 2014-04-07 23:49:35 (GMT) |
commit | 62b8c978ee6b8d135d9e7953221de58000dba986 (patch) | |
tree | 683b04b2e627f6710c22c151b23c8cc9a165315e /usr/gen_init_cpio.c | |
parent | 78fd82238d0e5716578c326404184a27ba67fd6e (diff) | |
download | linux-fsl-qoriq-62b8c978ee6b8d135d9e7953221de58000dba986.tar.xz |
Rewind v3.13-rc3+ (78fd82238d0e5716) to v3.12
Diffstat (limited to 'usr/gen_init_cpio.c')
-rw-r--r-- | usr/gen_init_cpio.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c index 225ad24..af8c925 100644 --- a/usr/gen_init_cpio.c +++ b/usr/gen_init_cpio.c @@ -382,15 +382,24 @@ error: static char *cpio_replace_env(char *new_location) { char expanded[PATH_MAX + 1]; - char *start, *end, *var; - - while ((start = strstr(new_location, "${")) && - (end = strchr(start + 2, '}'))) { - *start = *end = 0; - var = getenv(start + 2); - snprintf(expanded, sizeof expanded, "%s%s%s", - new_location, var ? var : "", end + 1); - strcpy(new_location, expanded); + char env_var[PATH_MAX + 1]; + char *start; + char *end; + + for (start = NULL; (start = strstr(new_location, "${")); ) { + end = strchr(start, '}'); + if (start < end) { + *env_var = *expanded = '\0'; + strncat(env_var, start + 2, end - start - 2); + strncat(expanded, new_location, start - new_location); + strncat(expanded, getenv(env_var), + PATH_MAX - strlen(expanded)); + strncat(expanded, end + 1, + PATH_MAX - strlen(expanded)); + strncpy(new_location, expanded, PATH_MAX); + new_location[PATH_MAX] = 0; + } else + break; } return new_location; |