From 56b51c16fdef8f5fd0566352302d375d55c9ffb7 Mon Sep 17 00:00:00 2001 From: Christos Zoulas Date: Mon, 22 Mar 2004 19:12:51 +0000 Subject: [PATCH] Don't return early, always cleanup [from me] Better diagnostics from unreadable files [debian] --- src/magic.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) 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) -- 2.50.1