]> granicus.if.org Git - file/commitdiff
After we map and byteswap, mprotect(2) the magic entries read-only
authorChristos Zoulas <christos@zoulas.com>
Tue, 19 Jan 2016 15:18:02 +0000 (15:18 +0000)
committerChristos Zoulas <christos@zoulas.com>
Tue, 19 Jan 2016 15:18:02 +0000 (15:18 +0000)
to prevent bugs.

src/apprentice.c

index d63f20f6b8d5c44c241ffbb67b232aeb2a2175f3..ce6234a09edf6e26c0a7f86cbde602601424fa88 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.245 2016/01/19 04:17:07 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.246 2016/01/19 15:09:21 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -2979,6 +2979,12 @@ apprentice_map(struct magic_set *ms, const char *fn)
 
        if (check_buffer(ms, map, dbname) != 0)
                goto error;
+#ifdef QUICK
+       if (mprotect(map->p, (size_t)st.st_size, PROT_READ) == -1) {
+               file_error(ms, errno, "cannot mprotect `%s'", dbname);
+               goto error;
+       }
+#endif
 
        free(dbname);
        return map;