]> granicus.if.org Git - file/commitdiff
Compile regex during the magic compilation process so that we catch bad
authorChristos Zoulas <christos@zoulas.com>
Tue, 6 May 2014 16:07:23 +0000 (16:07 +0000)
committerChristos Zoulas <christos@zoulas.com>
Tue, 6 May 2014 16:07:23 +0000 (16:07 +0000)
regular expressions early.

src/apprentice.c

index fe522f4336bd18be39426976f62bbda7aacfbc35..5440f8cc8b8fcf632b64bea3ec39ca32a0cd67d5 100644 (file)
@@ -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: