From: Christos Zoulas Date: Mon, 24 Oct 2016 15:21:07 +0000 (+0000) Subject: When loading multiple magic files as in -m foo.mgc:bar and one of them fails, X-Git-Tag: FILE5_29~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6f5e033daeb492bb41633376c17dbf707744a58c;p=file When loading multiple magic files as in -m foo.mgc:bar and one of them fails, don't free the magic list entries, since the second can load successfully and we'll still work. Print a warning though when that happens. Reported by Christoph Biedl --- diff --git a/src/apprentice.c b/src/apprentice.c index 1590b102..e99175f4 100644 --- a/src/apprentice.c +++ b/src/apprentice.c @@ -32,7 +32,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: apprentice.c,v 1.252 2016/09/11 13:53:02 christos Exp $") +FILE_RCSID("@(#)$File: apprentice.c,v 1.253 2016/09/13 13:14:44 christos Exp $") #endif /* lint */ #include "magic.h" @@ -452,7 +452,7 @@ apprentice_1(struct magic_set *ms, const char *fn, int action) #ifndef COMPILE_ONLY map = apprentice_map(ms, fn); if (map == (struct magic_map *)-1) - goto fail; + return -1; if (map == NULL) { if (ms->flags & MAGIC_CHECK) file_magwarn(ms, "using regular magic file `%s'", fn); @@ -464,7 +464,7 @@ apprentice_1(struct magic_set *ms, const char *fn, int action) for (i = 0; i < MAGIC_SETS; i++) { if (add_mlist(ms->mlist[i], map, i) == -1) { file_oomem(ms, sizeof(*ml)); - goto fail; + return -1; } } @@ -478,12 +478,6 @@ apprentice_1(struct magic_set *ms, const char *fn, int action) } } return 0; -fail: - for (i = 0; i < MAGIC_SETS; i++) { - mlist_free(ms->mlist[i]); - ms->mlist[i] = NULL; - } - return -1; #else return 0; #endif /* COMPILE_ONLY */ diff --git a/src/file.c b/src/file.c index 7a5a935d..c8f992a1 100644 --- a/src/file.c +++ b/src/file.c @@ -32,7 +32,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: file.c,v 1.170 2016/03/31 17:51:12 christos Exp $") +FILE_RCSID("@(#)$File: file.c,v 1.171 2016/05/17 15:52:45 christos Exp $") #endif /* lint */ #include "magic.h" @@ -431,6 +431,8 @@ private struct magic_set * load(const char *magicfile, int flags) { struct magic_set *magic = magic_open(flags); + const char *e; + if (magic == NULL) { (void)fprintf(stderr, "%s: %s\n", progname, strerror(errno)); return NULL; @@ -441,6 +443,8 @@ load(const char *magicfile, int flags) magic_close(magic); return NULL; } + if ((e = magic_error(magic)) != NULL) + (void)fprintf(stderr, "%s: Warning: %s\n", progname, e); return magic; }