]> 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 90fd91e718b4a545c7d8d5c32bdd849ae52e5d43..25ba606f07329234454238ce89d8eb4883f4e4ff 100644 (file)
@@ -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: