From: Christos Zoulas Date: Tue, 13 May 2014 16:44:24 +0000 (+0000) Subject: Roman I Khimov: X-Git-Tag: FILE5_19~43 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3f137e8194df4551e677c67133b7b2e181207034;p=file Roman I Khimov: access() can't handle NULL as first argument and we can end up calling it this way if inname is NULL in file_or_fd() and fd is a pipe. Issue spotted by clang static analysis. --- diff --git a/src/magic.c b/src/magic.c index 862375b4..d9c7fe35 100644 --- a/src/magic.c +++ b/src/magic.c @@ -33,7 +33,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: magic.c,v 1.81 2013/11/29 15:42:51 christos Exp $") +FILE_RCSID("@(#)$File: magic.c,v 1.82 2014/05/13 16:38:23 christos Exp $") #endif /* lint */ #include "magic.h" @@ -220,13 +220,15 @@ magic_open(int flags) private int unreadable_info(struct magic_set *ms, mode_t md, const char *file) { - /* We cannot open it, but we were able to stat it. */ - if (access(file, W_OK) == 0) - if (file_printf(ms, "writable, ") == -1) - return -1; - if (access(file, X_OK) == 0) - if (file_printf(ms, "executable, ") == -1) - return -1; + if (file) { + /* We cannot open it, but we were able to stat it. */ + if (access(file, W_OK) == 0) + if (file_printf(ms, "writable, ") == -1) + return -1; + if (access(file, X_OK) == 0) + if (file_printf(ms, "executable, ") == -1) + return -1; + } if (S_ISREG(md)) if (file_printf(ms, "regular file, ") == -1) return -1;