From: Christos Zoulas Date: Tue, 13 May 2014 16:38:23 +0000 (+0000) Subject: Roman I Khimov: X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=89a3f534891aca3eeda14988c4634f2547a84722;p=file Roman I Khimov: If file_reset() fails for some reason, we pass uninitialized sb to close_and_restore() which uses it for utimes(). Issue spotted by clang static analysis. --- diff --git a/src/magic.c b/src/magic.c index 22174b8f..3eed6aaf 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" @@ -345,6 +345,9 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd) int ispipe = 0; off_t pos = (off_t)-1; + if (file_reset(ms) == -1) + goto out; + /* * one extra for terminating '\0', and * some overlapping space for matches near EOF @@ -353,9 +356,6 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd) if ((buf = CAST(unsigned char *, malloc(HOWMANY + SLOP))) == NULL) return NULL; - if (file_reset(ms) == -1) - goto done; - switch (file_fsmagic(ms, inname, &sb)) { case -1: /* error */ goto done; @@ -434,6 +434,7 @@ done: if (pos != (off_t)-1) (void)lseek(fd, pos, SEEK_SET); close_and_restore(ms, inname, fd, &sb); +out: return rv == 0 ? file_getbuffer(ms) : NULL; }