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-Tag: FILE5_19~53 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eefb9959fd34297cff5144a075ce7728b21d8073;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 fe522f43..5440f8cc 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.206 2014/04/30 21:41:02 christos Exp $") +FILE_RCSID("@(#)$File: apprentice.c,v 1.207 2014/05/04 18:57:35 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: