diff options
author | Ron Yorston <rmy@pobox.com> | 2019-03-16 10:14:03 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2019-03-16 10:14:03 +0000 |
commit | 9d1ff6a7bd9f598e3d6fe7f9002204044a0c42fa (patch) | |
tree | 4644629e5613f92becf76d8acc2832ffd22c3b27 /shell | |
parent | f9b753e70101ddd708841cc942e2072e1163a260 (diff) | |
download | busybox-w32-9d1ff6a7bd9f598e3d6fe7f9002204044a0c42fa.tar.gz busybox-w32-9d1ff6a7bd9f598e3d6fe7f9002204044a0c42fa.tar.bz2 busybox-w32-9d1ff6a7bd9f598e3d6fe7f9002204044a0c42fa.zip |
ash: enforce ';' separator in CDPATH and MANPATH variables
Commit a23624237 (win32: special treatment for PATH) required the
PATH variable to use ';' as the separator between components and
enforced this by intercepting attempts to update it.
Do the same for the CDPATH and MANPATH variables.
Also, fix a case in cdcmd() where the wrong separator was used.
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/shell/ash.c b/shell/ash.c index 40cb9bce8..248f3f017 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -2460,13 +2460,13 @@ bltinlookup(const char *name) | |||
2460 | 2460 | ||
2461 | #if ENABLE_PLATFORM_MINGW32 | 2461 | #if ENABLE_PLATFORM_MINGW32 |
2462 | static char * | 2462 | static char * |
2463 | fix_pathvar(const char *path) | 2463 | fix_pathvar(const char *path, int len) |
2464 | { | 2464 | { |
2465 | char *newpath = xstrdup(path); | 2465 | char *newpath = xstrdup(path); |
2466 | char *p; | 2466 | char *p; |
2467 | int modified = FALSE; | 2467 | int modified = FALSE; |
2468 | 2468 | ||
2469 | p = newpath + 5; | 2469 | p = newpath + len; |
2470 | while (*p) { | 2470 | while (*p) { |
2471 | if (*p != ':' && *p != ';') { | 2471 | if (*p != ':' && *p != ';') { |
2472 | /* skip drive */ | 2472 | /* skip drive */ |
@@ -2507,14 +2507,26 @@ setvareq(char *s, int flags) | |||
2507 | struct var *vp, **vpp; | 2507 | struct var *vp, **vpp; |
2508 | 2508 | ||
2509 | #if ENABLE_PLATFORM_MINGW32 | 2509 | #if ENABLE_PLATFORM_MINGW32 |
2510 | if (strncmp(s, "PATH=", 5) == 0) { | 2510 | struct pathname { |
2511 | char *newpath = fix_pathvar(s); | 2511 | const char *name; |
2512 | if (newpath) { | 2512 | const int len; |
2513 | if ((flags & (VTEXTFIXED|VSTACK|VNOSAVE)) == VNOSAVE) | 2513 | } paths[] = { |
2514 | free(s); | 2514 | { "PATH=", sizeof("PATH=")-1 }, |
2515 | flags |= VNOSAVE; | 2515 | { "CDPATH=", sizeof("CDPATH=")-1 }, |
2516 | flags &= ~(VTEXTFIXED|VSTACK); | 2516 | { "MANPATH=", sizeof("MANPATH=")-1 }, |
2517 | s = newpath; | 2517 | }; |
2518 | int i; | ||
2519 | |||
2520 | for (i = 0; i < ARRAY_SIZE(paths); ++i) { | ||
2521 | if (strncmp(s, paths[i].name, paths[i].len) == 0) { | ||
2522 | char *newpath = fix_pathvar(s, paths[i].len); | ||
2523 | if (newpath) { | ||
2524 | if ((flags & (VTEXTFIXED|VSTACK|VNOSAVE)) == VNOSAVE) | ||
2525 | free(s); | ||
2526 | flags |= VNOSAVE; | ||
2527 | flags &= ~(VTEXTFIXED|VSTACK); | ||
2528 | s = newpath; | ||
2529 | } | ||
2518 | } | 2530 | } |
2519 | } | 2531 | } |
2520 | #endif | 2532 | #endif |
@@ -3156,7 +3168,7 @@ cdcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
3156 | c = *path; | 3168 | c = *path; |
3157 | p = path_advance(&path, dest); | 3169 | p = path_advance(&path, dest); |
3158 | if (stat(p, &statb) >= 0 && S_ISDIR(statb.st_mode)) { | 3170 | if (stat(p, &statb) >= 0 && S_ISDIR(statb.st_mode)) { |
3159 | if (c && c != ':') | 3171 | if (c && c != PATH_SEP) |
3160 | flags |= CD_PRINT; | 3172 | flags |= CD_PRINT; |
3161 | docd: | 3173 | docd: |
3162 | if (!docd(p, flags)) | 3174 | if (!docd(p, flags)) |