]> granicus.if.org Git - file/commitdiff
- avoid 0 offset causing an infinite loop.
authorChristos Zoulas <christos@zoulas.com>
Tue, 26 Feb 2013 18:24:43 +0000 (18:24 +0000)
committerChristos Zoulas <christos@zoulas.com>
Tue, 26 Feb 2013 18:24:43 +0000 (18:24 +0000)
- XXX: should limit indirect nesting.

src/softmagic.c

index c42ca19f577194dfa2b8c83a5f58fb14162235ab..22d1a2750f430989d07b31f7beef3fe247c4c11b 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.158 2013/01/06 20:22:16 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.159 2013/02/17 22:28:27 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -1617,6 +1617,12 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
 
                if (m->flag & INDIROFFADD) {
                        offset += ms->c.li[cont_level-1].off;
+                       if (offset == 0) {
+                               if ((ms->flags & MAGIC_DEBUG) != 0)
+                                       fprintf(stderr,
+                                           "indirect *zero* offset\n");
+                               return 0;
+                       }
                        if ((ms->flags & MAGIC_DEBUG) != 0)
                                fprintf(stderr, "indirect +offs=%u\n", offset);
                }