Do not segfault if PATH is unset.

This commit is contained in:
Matt Kraai 2002-01-14 18:30:10 +00:00
parent ba552523fa
commit a3181dd833
2 changed files with 18 additions and 9 deletions

View File

@ -38,15 +38,16 @@ extern int which_main(int argc, char **argv)
argc--; argc--;
path_list = getenv("PATH"); path_list = getenv("PATH");
if (!path_list) if (path_list != NULL) {
path_list = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin"; for(i=strlen(path_list); i > 0; i--)
if (path_list[i]==':') {
/* Replace colons with zeros in path_parsed and count them */ path_list[i]=0;
for(i=strlen(path_list); i > 0; i--) count++;
if (path_list[i]==':') { }
path_list[i]=0; } else {
count++; path_list = "/bin\0/sbin\0/usr/bin\0/usr/sbin\0/usr/local/bin";
} count = 5;
}
while(argc-- > 0) { while(argc-- > 0) {
path_n = path_list; path_n = path_list;

View File

@ -0,0 +1,8 @@
BUSYBOX=$(type -p busybox)
echo $BUSYBOX
SAVED_PATH=$PATH
unset PATH
$BUSYBOX which ls
STATUS=$?
export PATH=$SAVED_PATH
return $STATUS