From: Todd C. Miller Date: Wed, 8 Sep 1993 15:39:08 +0000 (+0000) Subject: fixed bug with non-executable tings of same name in path introduced by checkig errno X-Git-Tag: SUDO_1_3_0~94 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fde49b4c75763ac128e83b101d3be508d2bac5b1;p=sudo fixed bug with non-executable tings of same name in path introduced by checkig errno after stat(2). --- diff --git a/find_path.c b/find_path.c index c88ae80b0..ec8567916 100644 --- a/find_path.c +++ b/find_path.c @@ -77,7 +77,8 @@ char *find_path(file) register char *n; /* for traversing path */ char *path = NULL; /* contents of PATH env var */ char fn[MAXPATHLEN+1]; /* filename (path + file) */ - struct stat statbuf; /* for stat() */ + struct stat statbuf; /* for stat(2) */ + int statfailed; /* stat(2) return value */ char *qualify(); if (strlen(file) > MAXPATHLEN) { @@ -105,9 +106,10 @@ char *find_path(file) strcat(fn, file); /* stat the file to make sure it exists and is executable */ - if (!stat(fn, &statbuf) && (statbuf.st_mode & 0000111)) + statfailed = stat(fn, &statbuf); + if (!statfailed && (statbuf.st_mode & 0000111)) return (qualify(fn)); - else if (errno == ENOENT || errno == ENOTDIR) + else if (!statfailed || errno == ENOENT || errno == ENOTDIR) path=n+1; else { perror("find_path: stat");