diff options
author | Matt Kraai <kraai@debian.org> | 2002-01-14 18:30:10 +0000 |
---|---|---|
committer | Matt Kraai <kraai@debian.org> | 2002-01-14 18:30:10 +0000 |
commit | a3181dd833970b1aa99087c3e3647387116547f0 (patch) | |
tree | 60f79ccf57bb1028f73230e677ad628b21f28d16 | |
parent | ba552523fafaf687c6c6cf6113fe7b6c1b786920 (diff) | |
download | busybox-w32-a3181dd833970b1aa99087c3e3647387116547f0.tar.gz busybox-w32-a3181dd833970b1aa99087c3e3647387116547f0.tar.bz2 busybox-w32-a3181dd833970b1aa99087c3e3647387116547f0.zip |
Do not segfault if PATH is unset.
-rw-r--r-- | findutils/which.c | 19 | ||||
-rw-r--r-- | testsuite/which/which-uses-default-path | 8 |
2 files changed, 18 insertions, 9 deletions
diff --git a/findutils/which.c b/findutils/which.c index eec5fdbfb..b2af5a8ea 100644 --- a/findutils/which.c +++ b/findutils/which.c | |||
@@ -38,15 +38,16 @@ extern int which_main(int argc, char **argv) | |||
38 | argc--; | 38 | argc--; |
39 | 39 | ||
40 | path_list = getenv("PATH"); | 40 | path_list = getenv("PATH"); |
41 | if (!path_list) | 41 | if (path_list != NULL) { |
42 | path_list = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin"; | 42 | for(i=strlen(path_list); i > 0; i--) |
43 | 43 | if (path_list[i]==':') { | |
44 | /* Replace colons with zeros in path_parsed and count them */ | 44 | path_list[i]=0; |
45 | for(i=strlen(path_list); i > 0; i--) | 45 | count++; |
46 | if (path_list[i]==':') { | 46 | } |
47 | path_list[i]=0; | 47 | } else { |
48 | count++; | 48 | path_list = "/bin\0/sbin\0/usr/bin\0/usr/sbin\0/usr/local/bin"; |
49 | } | 49 | count = 5; |
50 | } | ||
50 | 51 | ||
51 | while(argc-- > 0) { | 52 | while(argc-- > 0) { |
52 | path_n = path_list; | 53 | path_n = path_list; |
diff --git a/testsuite/which/which-uses-default-path b/testsuite/which/which-uses-default-path new file mode 100644 index 000000000..e2a2f3893 --- /dev/null +++ b/testsuite/which/which-uses-default-path | |||
@@ -0,0 +1,8 @@ | |||
1 | BUSYBOX=$(type -p busybox) | ||
2 | echo $BUSYBOX | ||
3 | SAVED_PATH=$PATH | ||
4 | unset PATH | ||
5 | $BUSYBOX which ls | ||
6 | STATUS=$? | ||
7 | export PATH=$SAVED_PATH | ||
8 | return $STATUS | ||