]> 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 038a1ffc39564e64c940834865b317ec98af7327..9e8324cc24cd0a2fa815ce9395a9163b81d00259 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.159 2013/02/17 22:28:27 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.160 2013/02/26 18:24:43 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);
                }