Skip to content

Commit

Permalink
Roman I Khimov:
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zoulasc committed May 13, 2014
1 parent f28fbb9 commit 2d1b6fd
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/magic.c
Expand Up @@ -33,7 +33,7 @@
#include "file.h"

#ifndef lint
FILE_RCSID("@(#)$File: magic.c,v 1.80 2013/11/06 19:33:31 christos Exp $")
FILE_RCSID("@(#)$File: magic.c,v 1.81 2013/11/29 15:42:51 christos Exp $")
#endif /* lint */

#include "magic.h"
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -434,6 +434,7 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd)
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;
}

Expand Down

0 comments on commit 2d1b6fd

Please sign in to comment.