From a236242374daf911a01e998fabb1cc1268b2be7b Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Fri, 14 Dec 2018 15:27:54 +0000 Subject: win32: special treatment for PATH The PATH shell variable is a special case. It can be exported to the environment where it might be interpreted by native applications which assume the separator is ';'. Hence: - require that the separator used in PATH is ';' - enforce this by intercepting calls to setvareq() that set PATH and adjusting its value if necessary. As a result of this the code to parse PATH can be simplified by replacing the hardcoded Unix ':' path separator by the platform- dependent macro PATH_SEP. The MANPATH variable is also required to use ';' as its separator but since it's less likely to be used this isn't enforced. --- libbb/executable.c | 15 ++++----------- libbb/lineedit.c | 12 ++---------- 2 files changed, 6 insertions(+), 21 deletions(-) (limited to 'libbb') diff --git a/libbb/executable.c b/libbb/executable.c index 835341ed9..87a40eeda 100644 --- a/libbb/executable.c +++ b/libbb/executable.c @@ -40,28 +40,21 @@ char* FAST_FUNC find_executable(const char *filename, char **PATHp) */ char *p, *n; #if ENABLE_PLATFORM_MINGW32 - char sep, *w; + char *w; #endif p = *PATHp; while (p) { int ex; -#if !ENABLE_PLATFORM_MINGW32 - n = strchr(p, ':'); + n = strchr(p, PATH_SEP); if (n) *n = '\0'; -#else - n = (char*)next_path_sep(p); - if (n) { sep = *n; *n = '\0'; } -#endif p = concat_path_file( p[0] ? p : ".", /* handle "::" case */ filename ); -#if !ENABLE_PLATFORM_MINGW32 - if (n) *n++ = ':'; -#else - if (n) *n++ = sep; + if (n) *n++ = PATH_SEP; +#if ENABLE_PLATFORM_MINGW32 if ((w=alloc_win32_extension(p))) { free(p); p = w; diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 89178bbc3..6513219ce 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -798,11 +798,7 @@ static int path_parse(char ***p) tmp = (char*)pth; npth = 1; /* path component count */ while (1) { -#if ENABLE_PLATFORM_MINGW32 - tmp = (char *)next_path_sep(tmp); -#else - tmp = strchr(tmp, ':'); -#endif + tmp = strchr(tmp, PATH_SEP); if (!tmp) break; tmp++; @@ -815,11 +811,7 @@ static int path_parse(char ***p) res[0] = tmp = xstrdup(pth); npth = 1; while (1) { -#if ENABLE_PLATFORM_MINGW32 - tmp = (char *)next_path_sep(tmp); -#else - tmp = strchr(tmp, ':'); -#endif + tmp = strchr(tmp, PATH_SEP); if (!tmp) break; *tmp++ = '\0'; /* ':' -> '\0' */ -- cgit v1.2.3-55-g6feb