diff options
Diffstat (limited to 'usr/gen_init_cpio.c')
-rw-r--r-- | usr/gen_init_cpio.c | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c index af8c925e93eb..225ad244cf88 100644 --- a/usr/gen_init_cpio.c +++ b/usr/gen_init_cpio.c | |||
@@ -382,24 +382,15 @@ error: | |||
382 | static char *cpio_replace_env(char *new_location) | 382 | static char *cpio_replace_env(char *new_location) |
383 | { | 383 | { |
384 | char expanded[PATH_MAX + 1]; | 384 | char expanded[PATH_MAX + 1]; |
385 | char env_var[PATH_MAX + 1]; | 385 | char *start, *end, *var; |
386 | char *start; | 386 | |
387 | char *end; | 387 | while ((start = strstr(new_location, "${")) && |
388 | 388 | (end = strchr(start + 2, '}'))) { | |
389 | for (start = NULL; (start = strstr(new_location, "${")); ) { | 389 | *start = *end = 0; |
390 | end = strchr(start, '}'); | 390 | var = getenv(start + 2); |
391 | if (start < end) { | 391 | snprintf(expanded, sizeof expanded, "%s%s%s", |
392 | *env_var = *expanded = '\0'; | 392 | new_location, var ? var : "", end + 1); |
393 | strncat(env_var, start + 2, end - start - 2); | 393 | strcpy(new_location, expanded); |
394 | strncat(expanded, new_location, start - new_location); | ||
395 | strncat(expanded, getenv(env_var), | ||
396 | PATH_MAX - strlen(expanded)); | ||
397 | strncat(expanded, end + 1, | ||
398 | PATH_MAX - strlen(expanded)); | ||
399 | strncpy(new_location, expanded, PATH_MAX); | ||
400 | new_location[PATH_MAX] = 0; | ||
401 | } else | ||
402 | break; | ||
403 | } | 394 | } |
404 | 395 | ||
405 | return new_location; | 396 | return new_location; |