aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2024-06-14 08:12:08 +0100
committerRon Yorston <rmy@pobox.com>2024-06-14 08:12:08 +0100
commit9ee8e87d5affe019aeb2b8afe4b908672c4c2fa5 (patch)
tree177dc25062b8eadddc988c638920f417c77bb2b1 /libbb
parenta518a4f6023582744fa271ec279375dd3d51a4d4 (diff)
downloadbusybox-w32-9ee8e87d5affe019aeb2b8afe4b908672c4c2fa5.tar.gz
busybox-w32-9ee8e87d5affe019aeb2b8afe4b908672c4c2fa5.tar.bz2
busybox-w32-9ee8e87d5affe019aeb2b8afe4b908672c4c2fa5.zip
win32: allow for trailing separator in PATH
In recent versions of Windows the PATH environment variable has a trailing semicolon. This is insignificant to Windows because it's ignored. busybox-w32 conforms to the POSIX interpretation of PATH which treats an empty path element as denoting the current directory. As result, on these versions of Windows executables may by default be run from the current directory, contrary to usual Unix practice. Attempt to detect and remove the trailing semicolon on applet start up. If the user insists, they can add a trailing semicolon to the shell variable PATH and it will be respected in the conventional manner. Adds 88-112 bytes. (GitHub issue #422)
Diffstat (limited to 'libbb')
-rw-r--r--libbb/appletlib.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 1232d97c9..1f9968f10 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -1410,6 +1410,18 @@ int main(int argc UNUSED_PARAM, char **argv)
1410 if (s) 1410 if (s)
1411 *s = '\0'; 1411 *s = '\0';
1412 } 1412 }
1413
1414 if (windows_env()) {
1415 /* remove single trailing separator from PATH */
1416 for (char **envp = environ; envp && *envp; envp++) {
1417 if (is_prefixed_with_case(*envp, "PATH=")) {
1418 char *end = last_char_is(*envp, ';');
1419 if (end && end[-1] != ';')
1420 *end = '\0';
1421 break;
1422 }
1423 }
1424 }
1413# endif 1425# endif
1414 applet_name = bb_basename(applet_name); 1426 applet_name = bb_basename(applet_name);
1415 1427