]> granicus.if.org Git - file/commitdiff
Roman I Khimov:
authorChristos Zoulas <christos@zoulas.com>
Tue, 13 May 2014 16:38:23 +0000 (16:38 +0000)
committerChristos Zoulas <christos@zoulas.com>
Tue, 13 May 2014 16:38:23 +0000 (16:38 +0000)
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.

src/magic.c

index 22174b8f5234ec01af18fd79018dbb3e704e9eee..3eed6aaff74ee8132eac7a23cc7525b3902ade97 100644 (file)
@@ -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;
 }