From: Christos Zoulas Date: Tue, 6 May 2014 16:07:23 +0000 (+0000) Subject: Compile regex during the magic compilation process so that we catch bad X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2a8c672d540ef9bba9b200ee64abbccccdbc7b32;p=file Compile regex during the magic compilation process so that we catch bad regular expressions early. --- diff --git a/src/apprentice.c b/src/apprentice.c index 90fd91e7..25ba606f 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.207 2014/05/04 18:57:35 christos Exp $") +FILE_RCSID("@(#)$File: apprentice.c,v 1.208 2014/05/06 16:07:23 christos Exp $") #endif /* lint */ #include "magic.h" @@ -2378,6 +2378,16 @@ getvalue(struct magic_set *ms, struct magic *m, const char **p, int action) m->value.s); return -1; } + if (m->type == FILE_REGEX) { + file_regex_t rx; + int rc = file_regcomp(&rx, m->value.s, REG_EXTENDED); + if (rc) { + if (ms->flags & MAGIC_CHECK) + file_regerror(&rx, rc, ms); + } + file_regfree(&rx); + return rc ? -1 : 0; + } return 0; case FILE_FLOAT: case FILE_BEFLOAT: