summaryrefslogtreecommitdiff
path: root/findutils/which.c
diff options
context:
space:
mode:
authorMatt Kraai2002-01-14 18:30:10 +0000
committerMatt Kraai2002-01-14 18:30:10 +0000
commita3181dd833970b1aa99087c3e3647387116547f0 (patch)
tree60f79ccf57bb1028f73230e677ad628b21f28d16 /findutils/which.c
parentba552523fafaf687c6c6cf6113fe7b6c1b786920 (diff)
downloadbusybox-a3181dd833970b1aa99087c3e3647387116547f0.zip
busybox-a3181dd833970b1aa99087c3e3647387116547f0.tar.gz
Do not segfault if PATH is unset.
Diffstat (limited to 'findutils/which.c')
-rw-r--r--findutils/which.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/findutils/which.c b/findutils/which.c
index eec5fdb..b2af5a8 100644
--- a/findutils/which.c
+++ b/findutils/which.c
@@ -38,15 +38,16 @@ extern int which_main(int argc, char **argv)
argc--;
path_list = getenv("PATH");
- if (!path_list)
- path_list = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin";
-
- /* Replace colons with zeros in path_parsed and count them */
- for(i=strlen(path_list); i > 0; i--)
- if (path_list[i]==':') {
- path_list[i]=0;
- count++;
- }
+ if (path_list != NULL) {
+ for(i=strlen(path_list); i > 0; i--)
+ if (path_list[i]==':') {
+ path_list[i]=0;
+ count++;
+ }
+ } else {
+ path_list = "/bin\0/sbin\0/usr/bin\0/usr/sbin\0/usr/local/bin";
+ count = 5;
+ }
while(argc-- > 0) {
path_n = path_list;