]> granicus.if.org Git - file/commitdiff
Bumo string size to 96; don't try to parse a compiled file as a regular magic
authorChristos Zoulas <christos@zoulas.com>
Tue, 5 Jul 2016 19:20:19 +0000 (19:20 +0000)
committerChristos Zoulas <christos@zoulas.com>
Tue, 5 Jul 2016 19:20:19 +0000 (19:20 +0000)
file.

src/apprentice.c
src/file.h

index 38df328515ef23aa2b81e7be1d16e5fcdac8af49..37d19a21f5c8bd02fbb6ced8f03bf7b3c4fb0479 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.248 2016/03/31 17:51:12 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.249 2016/05/17 21:43:07 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -451,6 +451,8 @@ 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;
        if (map == NULL) {
                if (ms->flags & MAGIC_CHECK)
                        file_magwarn(ms, "using regular magic file `%s'", fn);
@@ -2930,6 +2932,7 @@ apprentice_map(struct magic_set *ms, const char *fn)
        struct stat st;
        char *dbname = NULL;
        struct magic_map *map;
+       struct magic_map *rv = NULL;
 
        fd = -1;
        if ((map = CAST(struct magic_map *, calloc(1, sizeof(*map)))) == NULL) {
@@ -2978,8 +2981,10 @@ apprentice_map(struct magic_set *ms, const char *fn)
        (void)close(fd);
        fd = -1;
 
-       if (check_buffer(ms, map, dbname) != 0)
+       if (check_buffer(ms, map, dbname) != 0) {
+               rv = (struct magic_map *)-1;
                goto error;
+       }
 #ifdef QUICK
        if (mprotect(map->p, (size_t)st.st_size, PROT_READ) == -1) {
                file_error(ms, errno, "cannot mprotect `%s'", dbname);
@@ -2995,7 +3000,7 @@ error:
                (void)close(fd);
        apprentice_unmap(map);
        free(dbname);
-       return NULL;
+       return rv;
 }
 
 private int
index c54d39e9a794c2a0e32ca4d4a3a64675e67bfefe..6693985b55cbfc95e7cf27060707d947ca287913 100644 (file)
@@ -27,7 +27,7 @@
  */
 /*
  * file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.177 2016/03/21 15:56:53 christos Exp $
+ * @(#)$File: file.h,v 1.178 2016/03/31 17:51:12 christos Exp $
  */
 
 #ifndef __file_h__
                                   or directory */
 #define MAXDESC        64              /* max len of text description/MIME type */
 #define MAXMIME        80              /* max len of text MIME type */
-#define MAXstring 64           /* max len of "string" types */
+#define MAXstring 96           /* max len of "string" types */
 
 #define MAGICNO                0xF11E041C
-#define VERSIONNO      13
-#define FILE_MAGICSIZE 312
+#define VERSIONNO      14
+#define FILE_MAGICSIZE 344
 
 #define        FILE_LOAD       0
 #define FILE_CHECK     1