]> granicus.if.org Git - file/commitdiff
- add more debugging for indirect offsets.
authorChristos Zoulas <christos@zoulas.com>
Fri, 6 Apr 2012 21:15:54 +0000 (21:15 +0000)
committerChristos Zoulas <christos@zoulas.com>
Fri, 6 Apr 2012 21:15:54 +0000 (21:15 +0000)
- only print the description for indirect offsets if a match was found,
  and add the offset as the number to print.

src/softmagic.c

index 3c47374b9105796b5b75b0ceedd3bf06f3096aa7..e5aeeea4e65bdcb458f40b55d38f8cdb570888e3 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.148 2012/04/03 22:25:07 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.149 2012/04/06 21:15:54 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -1034,6 +1034,8 @@ mget(struct magic_set *ms, const unsigned char *s,
 {
        uint32_t offset = ms->offset;
        uint32_t count = m->str_range;
+       int rv;
+       char *sbuf, *rbuf;
        union VALUETYPE *p = &ms->ms_value;
 
        if (mcopy(ms, p, m->type, m->flag & INDIR, s, offset, nbytes, count) == -1)
@@ -1082,6 +1084,8 @@ mget(struct magic_set *ms, const unsigned char *s,
                                                 (q->hl[3]<<8)|(q->hl[2]));
                                break;
                        }
+                       if ((ms->flags & MAGIC_DEBUG) != 0)
+                               fprintf(stderr, "indirect offs=%u\n", off);
                }
                switch (m->in_type) {
                case FILE_BYTE:
@@ -1522,6 +1526,8 @@ mget(struct magic_set *ms, const unsigned char *s,
 
                if (m->flag & INDIROFFADD) {
                        offset += ms->c.li[cont_level-1].off;
+                       if ((ms->flags & MAGIC_DEBUG) != 0)
+                               fprintf(stderr, "indirect +offs=%u\n", offset);
                }
                if (mcopy(ms, p, m->type, 0, s, offset, nbytes, count) == -1)
                        return -1;
@@ -1589,13 +1595,26 @@ mget(struct magic_set *ms, const unsigned char *s,
                break;
 
        case FILE_INDIRECT:
-               if ((ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0 &&
-                   file_printf(ms, "%s", m->desc) == -1)
-                       return -1;
                if (nbytes < offset)
                        return 0;
-               return file_softmagic(ms, s + offset, nbytes - offset,
+               sbuf = ms->o.buf;
+               ms->o.buf = NULL;
+               rv = file_softmagic(ms, s + offset, nbytes - offset,
                    BINTEST, text);
+               if ((ms->flags & MAGIC_DEBUG) != 0)
+                       fprintf(stderr, "indirect @offs=%u[%d]\n", offset, rv);
+               if (rv == 1) {
+                       rbuf = ms->o.buf;
+                       ms->o.buf = sbuf;
+                       if ((ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0 &&
+                           file_printf(ms, m->desc, offset) == -1)
+                               return -1;
+                       if (file_printf(ms, "%s", rbuf) == -1)
+                               return -1;
+                       free(rbuf);
+               } else
+                       ms->o.buf = sbuf;
+               return rv;
 
        case FILE_DEFAULT:      /* nothing to check */
        default: