]> granicus.if.org Git - file/commitdiff
Always reset state in {file,buffer}_apprentice (Krzysztof Wilczynski)
authorChristos Zoulas <christos@zoulas.com>
Mon, 28 Aug 2017 13:39:18 +0000 (13:39 +0000)
committerChristos Zoulas <christos@zoulas.com>
Mon, 28 Aug 2017 13:39:18 +0000 (13:39 +0000)
ChangeLog
src/apprentice.c
src/file.h
src/funcs.c
src/magic.c

index 4c78adeb18fd3c0231bc6bdaec21b9a62b68d546..596f512190058d06bb4bafd6c3b874d312cb23e3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2017-08-28  16:37  Christos Zoulas <christos@zoulas.com>
+
+       * Always reset state in {file,buffer}_apprentice (Krzysztof Wilczynski)
+
 2017-05-24  17:30  Christos Zoulas <christos@zoulas.com>
 
        * pickier parsing of numeric values in magic files.
index efa440b7411b6f559f1e89baa9b7e74c75ad28fb..a7b4dd8f9115be3b3ada2542c5ee605b77ccd3c9 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.261 2017/05/25 20:34:59 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.262 2017/08/28 13:39:18 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -612,8 +612,7 @@ buffer_apprentice(struct magic_set *ms, struct magic **bufs,
        if (nbufs == 0)
                return -1;
 
-       if (ms->mlist[0] != NULL)
-               file_reset(ms);
+       (void)file_reset(ms, 0);
 
        init_file_tables();
 
@@ -656,8 +655,7 @@ file_apprentice(struct magic_set *ms, const char *fn, int action)
        int file_err, errs = -1;
        size_t i;
 
-       if (ms->mlist[0] != NULL)
-               file_reset(ms);
+       (void)file_reset(ms, 0);
 
        if ((fn = magic_getpath(fn, action)) == NULL)
                return -1;
index 1229959fa474de542424e109d13e24a1ac7a7a0a..eb9c05421db6c3cb5ff51319a2e9adc833fd07b7 100644 (file)
@@ -27,7 +27,7 @@
  */
 /*
  * file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.182 2017/04/07 19:46:44 christos Exp $
+ * @(#)$File: file.h,v 1.183 2017/08/28 13:39:18 christos Exp $
  */
 
 #ifndef __file_h__
@@ -447,7 +447,7 @@ protected size_t file_printedlen(const struct magic_set *);
 protected int file_replace(struct magic_set *, const char *, const char *);
 protected int file_printf(struct magic_set *, const char *, ...)
     __attribute__((__format__(__printf__, 2, 3)));
-protected int file_reset(struct magic_set *);
+protected int file_reset(struct magic_set *, int);
 protected int file_tryelf(struct magic_set *, int, const unsigned char *,
     size_t);
 protected int file_trycdf(struct magic_set *, int, const unsigned char *,
index 33778ff1c100e663c3c510423e9e16410e095c52..d7a18f451a7e99364b37022947f58b3418f89050 100644 (file)
@@ -27,7 +27,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: funcs.c,v 1.92 2017/04/07 20:10:24 christos Exp $")
+FILE_RCSID("@(#)$File: funcs.c,v 1.93 2017/08/28 13:39:18 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -328,9 +328,9 @@ simple:
 #endif
 
 protected int
-file_reset(struct magic_set *ms)
+file_reset(struct magic_set *ms, int checkloaded)
 {
-       if (ms->mlist[0] == NULL) {
+       if (checkloaded && ms->mlist[0] == NULL) {
                file_error(ms, 0, "no magic files loaded");
                return -1;
        }
index 9ea3f8a1825818804c685a65ea3553052378e516..1448a69bcad5216f62e1e1a7cfd2af7397bf44b2 100644 (file)
@@ -33,7 +33,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: magic.c,v 1.101 2017/05/23 21:54:07 christos Exp $")
+FILE_RCSID("@(#)$File: magic.c,v 1.102 2017/08/28 13:39:18 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -167,7 +167,7 @@ DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
 {
        if (fdwReason == DLL_PROCESS_ATTACH)
                _w32_dll_instance = hinstDLL;
-       return TRUE;
+       return 1;
 }
 #endif
 
@@ -409,7 +409,7 @@ 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)
+       if (file_reset(ms, 1) == -1)
                goto out;
 
        /*
@@ -538,7 +538,7 @@ magic_buffer(struct magic_set *ms, const void *buf, size_t nb)
 {
        if (ms == NULL)
                return NULL;
-       if (file_reset(ms) == -1)
+       if (file_reset(ms, 1) == -1)
                return NULL;
        /*
         * The main work is done here!