fix a bug where `which' doesn't check whether the file passed as an argument
authorGlenn L McGrath <bug1@ihug.co.nz>
Wed, 29 Oct 2003 04:50:35 +0000 (04:50 -0000)
committerGlenn L McGrath <bug1@ihug.co.nz>
Wed, 29 Oct 2003 04:50:35 +0000 (04:50 -0000)
is a regular file, patch by Arthur Othieno

debianutils/which.c

index 27646d5..120f1e7 100644 (file)
@@ -30,7 +30,9 @@ static int file_exists(char *file)
 {
        struct stat filestat;
 
-       if (stat(file, &filestat) == 0 && filestat.st_mode & S_IXUSR)
+       if (stat(file, &filestat) == 0 &&
+                       S_ISREG(filestat.st_mode) &&
+                       filestat.st_mode & S_IXUSR)
                return 1;
        else
                return 0;