Nmap Development mailing list archives
Re: fileexistsandisreadable() is still broken
From: Diman Todorov <diman.todorov () chello at>
Date: Mon, 11 Dec 2006 21:20:46 +0100
On 11.12.2006, at 19:46, Kris Katterjohn wrote:
Fyodor wrote:On Tue, Sep 05, 2006 at 01:14:34PM -0500, Kris Katterjohn wrote:The attached patch fixes fileexistsandisreadable() in nmap.cc by using access() to test for readability instead of bitwise ANDing the mode and S_IRUSR. S_IRUSR only tests to see if the FILE's owner has readThanks. This looks good and I've applied it for the next version. Cheers, -FIn 4.21ALPHA1: #ifdef WIN32 #define STAT_READABLE(st) st.st_mode & S_IREAD #else #define STAT_READABLE(st) st.st_mode & S_IRUSR #endif /* Returns true (nonzero) if the file pathname given exists, is not * a directory and is readable by the executing process. Returns * zero if it is not */ int fileexistsandisreadable(char *pathname) { struct stat st; if (stat(pathname, &st) == -1) return 0; if (!S_ISDIR(st.st_mode) && STAT_READABLE(st)) return 1; if ((st.st_mode & S_IFDIR) && STAT_READABLE(st)) return 2; return 0; }
The reason why I modified this function is because I needed it to distinguish between files and directories. Before my changes it only considered files. I slightly changed it to tell me if a file or directory exists and is readable. My changes don't have anything to do with access(). As long as the semantics remain the same, a change is probably justified cheers Diman _______________________________________________ Sent through the nmap-dev mailing list http://cgi.insecure.org/mailman/listinfo/nmap-dev Archived at http://SecLists.Org
Current thread:
- fileexistsandisreadable() is still broken Kris Katterjohn (Dec 11)
- Re: fileexistsandisreadable() is still broken Diman Todorov (Dec 11)
- Re: fileexistsandisreadable() is still broken Kris Katterjohn (Dec 11)
- Re: fileexistsandisreadable() is still broken Fyodor (Dec 12)
- Re: fileexistsandisreadable() is still broken Diman Todorov (Dec 11)