]> 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 1a9a921207301fc15ba07041d0918485a9d5575d..ca82abbe818031af522955c186390d78a9bede49 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.246 2016/01/19 15:09:21 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.247 2016/01/19 15:18:02 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;