From: Christos Zoulas Date: Tue, 19 Jan 2016 15:18:02 +0000 (+0000) Subject: After we map and byteswap, mprotect(2) the magic entries read-only X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b1df343ba4718aa3b682f7315e576cba8cbe6e8a;p=file After we map and byteswap, mprotect(2) the magic entries read-only to prevent bugs. --- diff --git a/src/apprentice.c b/src/apprentice.c index 1a9a9212..ca82abbe 100644 --- a/src/apprentice.c +++ b/src/apprentice.c @@ -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;