diff options
| author | Ron Yorston <rmy@pobox.com> | 2026-02-01 09:29:44 +0000 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2026-02-01 09:29:44 +0000 |
| commit | e27f759c63b338e6e6cf6dc8d9d0711e9c05d6a5 (patch) | |
| tree | fa5987a920e978603c2fad778e056f7a76b89a2b /libbb/executable.c | |
| parent | 7f32f25ba1652f799e9e7ffe756dcee08c710e70 (diff) | |
| download | busybox-w32-e27f759c63b338e6e6cf6dc8d9d0711e9c05d6a5.tar.gz busybox-w32-e27f759c63b338e6e6cf6dc8d9d0711e9c05d6a5.tar.bz2 busybox-w32-e27f759c63b338e6e6cf6dc8d9d0711e9c05d6a5.zip | |
libbb: fix regression where 'which' output duplicate slashes
If an element of $PATH had a trailing slash 'which' displayed two
slashes when an executable was found in that directory.
This is a regression caused by upstream commit 49d9e06fb (libbb:
modify find_executable() to not temporarily write to PATH).
Prior to this commit find_executable() used concat_path_file() to
build the path of the executable. This avoids including duplicate
slashes in its output. The new code didn't.
Add a test in find_executable() to detect the problem. It still
fails if there are multiple trailing slashes. Don't do that.
Adds 48 bytes.
Diffstat (limited to 'libbb/executable.c')
| -rw-r--r-- | libbb/executable.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/libbb/executable.c b/libbb/executable.c index 263141912..57969033c 100644 --- a/libbb/executable.c +++ b/libbb/executable.c | |||
| @@ -50,6 +50,14 @@ char* FAST_FUNC find_executable(const char *name, const char **PATHp) | |||
| 50 | int ex; | 50 | int ex; |
| 51 | 51 | ||
| 52 | if (sz != 0) { | 52 | if (sz != 0) { |
| 53 | #if ENABLE_PLATFORM_MINGW32 | ||
| 54 | // Strip trailing slash from path | ||
| 55 | if (is_dir_sep(end[-1])) | ||
| 56 | --sz; | ||
| 57 | if (sz == 0) // "/" in PATH, unlikely but not impossible | ||
| 58 | p = xasprintf("%.*s/%s" + 4, name); | ||
| 59 | else | ||
| 60 | #endif | ||
| 53 | p = xasprintf("%.*s/%s", sz, p, name); | 61 | p = xasprintf("%.*s/%s", sz, p, name); |
| 54 | } else { | 62 | } else { |
| 55 | /* We have xxx::yyy in $PATH, | 63 | /* We have xxx::yyy in $PATH, |
