From: Christos Zoulas Date: Mon, 22 Mar 2004 19:12:51 +0000 (+0000) Subject: Don't return early, always cleanup [from me] X-Git-Tag: FILE4_08~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=483035da9ed5c938f456cf649fb373a411ecb669;p=file Don't return early, always cleanup [from me] Better diagnostics from unreadable files [debian] --- diff --git a/src/magic.c b/src/magic.c index 835f6359..96cdba72 100644 --- a/src/magic.c +++ b/src/magic.c @@ -65,7 +65,7 @@ #include "patchlevel.h" #ifndef lint -FILE_RCSID("@(#)$Id: magic.c,v 1.17 2003/12/23 17:32:30 christos Exp $") +FILE_RCSID("@(#)$Id: magic.c,v 1.18 2004/03/22 19:12:51 christos Exp $") #endif /* lint */ #ifdef __EMX__ @@ -240,6 +240,11 @@ magic_file(struct magic_set *ms, const char *inname) if (sb.st_mode & 0111) if (file_printf(ms, "executable, ") == -1) return NULL; + if (sb.st_mode & 0100000) + if (file_printf(ms, "regular file, ") == -1) + return NULL; + if (file_printf(ms, "no read permission") == -1) + return NULL; return file_getbuffer(ms); } @@ -253,10 +258,13 @@ magic_file(struct magic_set *ms, const char *inname) if (nbytes == 0) { if (file_printf(ms, (ms->flags & MAGIC_MIME) ? - "application/x-empty" : "empty") == -1) { - (void)close(fd); - goto done; - } + "application/x-empty" : "empty") == -1) + goto done; + goto gotit; + } else if (nbytes == 1) { + if (file_printf(ms, "very short file (no magic)") == -1) + goto done; + goto gotit; } else { buf[nbytes] = '\0'; /* null-terminate it */ #ifdef __EMX__ @@ -266,7 +274,7 @@ magic_file(struct magic_set *ms, const char *inname) case 0: break; default: - return file_getbuffer(ms); + goto gotit; } #endif if (file_buffer(ms, buf, (size_t)nbytes) == -1)