]> granicus.if.org Git - file/commitdiff
When loading multiple magic files as in -m foo.mgc:bar and one of them fails,
authorChristos Zoulas <christos@zoulas.com>
Mon, 24 Oct 2016 15:21:07 +0000 (15:21 +0000)
committerChristos Zoulas <christos@zoulas.com>
Mon, 24 Oct 2016 15:21:07 +0000 (15:21 +0000)
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

src/apprentice.c
src/file.c

index 1590b10210723a337d679f1bfaedc90364aad3e5..e99175f4a6594a708397b674e096e9cf9c607d41 100644 (file)
@@ -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 */
index 7a5a935db8dee92f382be669b042b4f9576ecc91..c8f992a15d0fce6b68efd8b749a5f8124a3e9cf2 100644 (file)
@@ -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;
 }