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 27646d520a43784767bc8f93215418e63bd7be49..120f1e72f216e76dc6a97193b2500cef1376603b 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;