]> granicus.if.org Git - file/commitdiff
Remove name recursion limit, it is always lower than the count... Rename
authorChristos Zoulas <christos@zoulas.com>
Fri, 28 Nov 2014 02:46:39 +0000 (02:46 +0000)
committerChristos Zoulas <christos@zoulas.com>
Fri, 28 Nov 2014 02:46:39 +0000 (02:46 +0000)
things for consistency.

doc/file.man
doc/libmagic.man
src/apprentice.c
src/ascmagic.c
src/elfclass.h
src/file.c
src/file.h
src/funcs.c
src/magic.c
src/softmagic.c

index 9378b5b3b46ecca5b66164be2b3b1d1990edaf32..9a0c6f42a52cc513239ea193dd0b21df7827d4e5 100644 (file)
@@ -1,4 +1,4 @@
-.\" $File: file.man,v 1.109 2014/11/28 02:35:05 christos Exp $
+.\" $File: file.man,v 1.110 2014/11/28 02:46:39 christos Exp $
 .Dd November 27, 2014
 .Dt FILE __CSECTION__
 .Os
@@ -306,13 +306,12 @@ attempt to preserve the access time of files analyzed, to pretend that
 never read them.
 .It Fl P , Fl Fl parameter Ar name=value
 Set various parameter limits.
-.Bl -column "namenum" "Default" "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -offset indent
+.Bl -column "elf_phnum" "Default" "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -offset indent
 .It Sy "Name" Ta Sy "Default" Ta Sy "Explanation"
 .It Li indir Ta 15 Ta recursion limit for indirect magic
-.It Li name Ta 40 Ta recursion limit for name/use magic
-.It Li namenum Ta 30 Ta use count limit for name/use magic
-.It Li phnum Ta 128 Ta max ELF program sections processed
-.It Li shnum Ta 32768 Ta max ELF sections processed
+.It Li name Ta 30 Ta use count limit for name/use magic
+.It Li elf_phnum Ta 128 Ta max ELF program sections processed
+.It Li elf_shnum Ta 32768 Ta max ELF sections processed
 .El
 .It Fl r , Fl Fl raw
 Don't translate unprintable characters to \eooo.
index 34a36c93a6fdd631b7f9dc1f4418a258589ad3f5..537cd7b70d58b4566c9d42c62ea3e573f505dc85 100644 (file)
@@ -1,4 +1,4 @@
-.\" $File: libmagic.man,v 1.32 2014/11/28 02:35:05 christos Exp $
+.\" $File: libmagic.man,v 1.33 2014/11/28 02:46:39 christos Exp $
 .\"
 .\" Copyright (c) Christos Zoulas 2003.
 .\" All Rights Reserved.
@@ -280,13 +280,12 @@ and
 .Fn magic_setparam
 allow getting and setting various limits related to the the magic
 library.
-.Bl -column "MAGIC_PARAM_INDIR_RECURSION" "size_t" "Default" -offset indent
+.Bl -column "MAGIC_PARAM_ELF_PHNUM_MAX" "size_t" "Default" -offset indent
 .It Sy "Parameter" Ta Sy "Type" Ta Sy "Default"
-.It Li MAGIC_PARAM_INDIR_RECURSION Ta size_t Ta 15
-.It Li MAGIC_PARAM_NAME_RECURSION Ta size_t Ta 40
+.It Li MAGIC_PARAM_INDIR_MAX Ta size_t Ta 15
 .It Li MAGIC_PARAM_NAME_MAX Ta size_t Ta 30
-.It Li MAGIC_PARAM_PHNUM_MAX Ta size_t Ta 128
-.It Li MAGIC_PARAM_SHNUM_MAX Ta size_t Ta 32768
+.It Li MAGIC_PARAM_ELF_PHNUM_MAX Ta size_t Ta 128
+.It Li MAGIC_PARAM_ELF_SHNUM_MAX Ta size_t Ta 32768
 .El
 .Pp
 The
index 1e93df786ce2448084d2490020632029e226580f..cfea6bee4e8b724d07d8e02c60ef9267667b85d2 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.226 2014/11/28 02:35:05 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.227 2014/11/28 02:46:39 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -524,11 +524,10 @@ file_ms_alloc(int flags)
                ms->mlist[i] = NULL;
        ms->file = "unknown";
        ms->line = 0;
-       ms->indir_recursion = FILE_INDIR_RECURSION;
-       ms->name_recursion = FILE_NAME_RECURSION;
+       ms->indir_max = FILE_INDIR_MAX;
        ms->name_max = FILE_NAME_MAX;
-       ms->shnum_max = FILE_ELF_SHNUM;
-       ms->phnum_max = FILE_ELF_PHNUM;
+       ms->elf_shnum_max = FILE_ELF_SHNUM_MAX;
+       ms->elf_phnum_max = FILE_ELF_PHNUM_MAX;
        return ms;
 free:
        free(ms);
index 8424c432d903482f3932d39c72f64135b3227123..78a6dbb7c84884693d9d1cdfa564c9ffb3c0b755 100644 (file)
@@ -35,7 +35,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: ascmagic.c,v 1.90 2014/11/28 02:35:05 christos Exp $")
+FILE_RCSID("@(#)$File: ascmagic.c,v 1.91 2014/11/28 02:46:39 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -147,7 +147,7 @@ file_ascmagic_with_encoding(struct magic_set *ms, const unsigned char *buf,
                    == NULL)
                        goto done;
                if ((rv = file_softmagic(ms, utf8_buf,
-                   (size_t)(utf8_end - utf8_buf), 0, 0, NULL,
+                   (size_t)(utf8_end - utf8_buf), 0, NULL,
                    TEXTTEST, text)) == 0)
                        rv = -1;
        }
index bda53b343e3191047d3f6550d035e54b1a0a73cf..e144d1127e4e777b29e14d30588c3d5184809b15 100644 (file)
@@ -36,7 +36,7 @@
 #ifdef ELFCORE
        case ET_CORE:
                phnum = elf_getu16(swap, elfhdr.e_phnum);
-               if (phnum > ms->phnum_max)
+               if (phnum > ms->elf_phnum_max)
                        return toomany(ms, "program", phnum);
                flags |= FLAGS_IS_CORE;
                if (dophn_core(ms, clazz, swap, fd,
        case ET_EXEC:
        case ET_DYN:
                phnum = elf_getu16(swap, elfhdr.e_phnum);
-               if (phnum > ms->phnum_max)
+               if (phnum > ms->elf_phnum_max)
                        return toomany(ms, "program", phnum);
                shnum = elf_getu16(swap, elfhdr.e_shnum);
-               if (shnum > ms->shnum_max)
+               if (shnum > ms->elf_shnum_max)
                        return toomany(ms, "section", shnum);
                if (dophn_exec(ms, clazz, swap, fd,
                    (off_t)elf_getu(swap, elfhdr.e_phoff), phnum,
@@ -62,7 +62,7 @@
                /*FALLTHROUGH*/
        case ET_REL:
                shnum = elf_getu16(swap, elfhdr.e_shnum);
-               if (shnum > ms->shnum_max)
+               if (shnum > ms->elf_shnum_max)
                        return toomany(ms, "section", shnum);
                if (doshn(ms, clazz, swap, fd,
                    (off_t)elf_getu(swap, elfhdr.e_shoff), shnum,
index e9b4cd81ab7d495d837f66ea867a536db021e365..148f806f172c8e4e925aaee43cc015b7d6783976 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: file.c,v 1.158 2014/11/28 02:35:05 christos Exp $")
+FILE_RCSID("@(#)$File: file.c,v 1.159 2014/11/28 02:46:39 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -121,11 +121,10 @@ private struct {
        int tag;
        size_t value;
 } pm[] = {
-       { "indir",      MAGIC_PARAM_INDIR_RECURSION, 0 },
-       { "name",       MAGIC_PARAM_NAME_RECURSION, 0 },
-       { "namenum",    MAGIC_PARAM_NAME_MAX, 0 },
-       { "phnum",      MAGIC_PARAM_PHNUM_MAX, 0 },
-       { "shnum",      MAGIC_PARAM_SHNUM_MAX, 0 },
+       { "indir",      MAGIC_PARAM_INDIR_MAX, 0 },
+       { "name",       MAGIC_PARAM_NAME_MAX, 0 },
+       { "elf_phnum",  MAGIC_PARAM_ELF_PHNUM_MAX, 0 },
+       { "elf_shnum",  MAGIC_PARAM_ELF_SHNUM_MAX, 0 },
 };
 
 private char *progname;                /* used throughout              */
index a0684d65a570417f4523f6cb771884d180af893a..7a8fea70ab9922b56d10d12f5075ef0dc1b4bd24 100644 (file)
@@ -27,7 +27,7 @@
  */
 /*
  * file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.159 2014/11/28 02:35:05 christos Exp $
+ * @(#)$File: file.h,v 1.160 2014/11/28 02:46:39 christos Exp $
  */
 
 #ifndef __file_h__
@@ -401,16 +401,14 @@ struct magic_set {
        /* FIXME: Make the string dynamically allocated so that e.g.
           strings matched in files can be longer than MAXstring */
        union VALUETYPE ms_value;       /* either number or string */
-       uint16_t indir_recursion;
-       uint16_t name_recursion;
+       uint16_t indir_max;
        uint16_t name_max;
-       uint16_t shnum_max;
-       uint16_t phnum_max;
-#define        FILE_INDIR_RECURSION    15
-#define        FILE_NAME_RECURSION     40
-#define        FILE_NAME_MAX           30
-#define        FILE_ELF_SHNUM          32768
-#define        FILE_ELF_PHNUM          128
+       uint16_t elf_shnum_max;
+       uint16_t elf_phnum_max;
+#define        FILE_INDIR_MAX                  15
+#define        FILE_NAME_MAX                   30
+#define        FILE_ELF_SHNUM_MAX              32768
+#define        FILE_ELF_PHNUM_MAX              128
 };
 
 /* Type for Unicode characters */
@@ -450,7 +448,7 @@ protected int file_encoding(struct magic_set *, const unsigned char *, size_t,
     unichar **, size_t *, const char **, const char **, const char **);
 protected int file_is_tar(struct magic_set *, const unsigned char *, size_t);
 protected int file_softmagic(struct magic_set *, const unsigned char *, size_t,
-    uint16_t, uint16_t, uint16_t *, int, int);
+    uint16_t, uint16_t *, int, int);
 protected int file_apprentice(struct magic_set *, const char *, int);
 protected int buffer_apprentice(struct magic_set *, struct magic **,
     size_t *, size_t);
index 0b2f6e5334b7664244197d048a40a96f200f324a..f190349fd909fee7b8698bce045e649285d8e421 100644 (file)
@@ -27,7 +27,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: funcs.c,v 1.76 2014/11/28 02:35:05 christos Exp $")
+FILE_RCSID("@(#)$File: funcs.c,v 1.77 2014/11/28 02:46:39 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -227,7 +227,7 @@ file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((unu
 
        /* try soft magic tests */
        if ((ms->flags & MAGIC_NO_CHECK_SOFT) == 0)
-               if ((m = file_softmagic(ms, ubuf, nb, 0, 0, NULL, BINTEST,
+               if ((m = file_softmagic(ms, ubuf, nb, 0, NULL, BINTEST,
                    looks_text)) != 0) {
                        if ((ms->flags & MAGIC_DEBUG) != 0)
                                (void)fprintf(stderr, "softmagic %d\n", m);
index 83af775905cff4df44f84990ea03421fc23a8055..d8cc04c5ece8c8324011bd4aacfb7e2589b25300 100644 (file)
@@ -33,7 +33,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: magic.c,v 1.88 2014/11/28 02:35:05 christos Exp $")
+FILE_RCSID("@(#)$File: magic.c,v 1.89 2014/11/28 02:46:39 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -541,20 +541,17 @@ public int
 magic_setparam(struct magic_set *ms, int param, const void *val)
 {
        switch (param) {
-       case MAGIC_PARAM_INDIR_RECURSION:
-               ms->indir_recursion = *(const size_t *)val;
-               return 0;
-       case MAGIC_PARAM_NAME_RECURSION:
-               ms->name_recursion = *(const size_t *)val;
+       case MAGIC_PARAM_INDIR_MAX:
+               ms->indir_max = *(const size_t *)val;
                return 0;
        case MAGIC_PARAM_NAME_MAX:
                ms->name_max = *(const size_t *)val;
                return 0;
-       case MAGIC_PARAM_PHNUM_MAX:
-               ms->phnum_max = *(const size_t *)val;
+       case MAGIC_PARAM_ELF_PHNUM_MAX:
+               ms->elf_phnum_max = *(const size_t *)val;
                return 0;
-       case MAGIC_PARAM_SHNUM_MAX:
-               ms->shnum_max = *(const size_t *)val;
+       case MAGIC_PARAM_ELF_SHNUM_MAX:
+               ms->elf_shnum_max = *(const size_t *)val;
                return 0;
        default:
                errno = EINVAL;
@@ -566,20 +563,17 @@ public int
 magic_getparam(struct magic_set *ms, int param, void *val)
 {
        switch (param) {
-       case MAGIC_PARAM_INDIR_RECURSION:
-               *(size_t *)val = ms->indir_recursion;
-               return 0;
-       case MAGIC_PARAM_NAME_RECURSION:
-               *(size_t *)val = ms->name_recursion;
+       case MAGIC_PARAM_INDIR_MAX:
+               *(size_t *)val = ms->indir_max;
                return 0;
        case MAGIC_PARAM_NAME_MAX:
                *(size_t *)val = ms->name_max;
                return 0;
-       case MAGIC_PARAM_PHNUM_MAX:
-               *(size_t *)val = ms->phnum_max;
+       case MAGIC_PARAM_ELF_PHNUM_MAX:
+               *(size_t *)val = ms->elf_phnum_max;
                return 0;
-       case MAGIC_PARAM_SHNUM_MAX:
-               *(size_t *)val = ms->shnum_max;
+       case MAGIC_PARAM_ELF_SHNUM_MAX:
+               *(size_t *)val = ms->elf_shnum_max;
                return 0;
        default:
                errno = EINVAL;
index 0ae446719884c4d54d592381cc8e6e1013a1f2c5..c9c2acb09c69948c6a5e761c688cd6ef03bbe0b7 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.201 2014/11/28 02:35:05 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.202 2014/11/28 02:46:39 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -43,11 +43,11 @@ FILE_RCSID("@(#)$File: softmagic.c,v 1.201 2014/11/28 02:35:05 christos Exp $")
 #include <time.h>
 
 private int match(struct magic_set *, struct magic *, uint32_t,
-    const unsigned char *, size_t, size_t, int, int, int, uint16_t, uint16_t,
+    const unsigned char *, size_t, size_t, int, int, int, uint16_t,
     uint16_t *, int *, int *, int *);
 private int mget(struct magic_set *, const unsigned char *,
     struct magic *, size_t, size_t, unsigned int, int, int, int, uint16_t,
-    uint16_t, uint16_t *, int *, int *, int *);
+    uint16_t *, int *, int *, int *);
 private int magiccheck(struct magic_set *, struct magic *);
 private int32_t mprint(struct magic_set *, struct magic *);
 private int32_t moffset(struct magic_set *, struct magic *);
@@ -71,8 +71,7 @@ private void cvt_64(union VALUETYPE *, const struct magic *);
 /*ARGSUSED1*/          /* nbytes passed for regularity, maybe need later */
 protected int
 file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes,
-    uint16_t indir_level, uint16_t name_level, uint16_t *name_count,
-       int mode, int text)
+    uint16_t indir_level, uint16_t *name_count, int mode, int text)
 {
        struct mlist *ml;
        int rv, printed_something = 0, need_separator = 0;
@@ -85,7 +84,7 @@ file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes,
 
        for (ml = ms->mlist[0]->next; ml != ms->mlist[0]; ml = ml->next)
                if ((rv = match(ms, ml->magic, ml->nmagic, buf, nbytes, 0, mode,
-                   text, 0, indir_level, name_level, name_count,
+                   text, 0, indir_level, name_count,
                    &printed_something, &need_separator, NULL)) != 0)
                        return rv;
 
@@ -141,7 +140,7 @@ file_fmtcheck(struct magic_set *ms, const struct magic *m, const char *def,
 private int
 match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
     const unsigned char *s, size_t nbytes, size_t offset, int mode, int text,
-    int flip, uint16_t indir_level, uint16_t name_level, uint16_t *name_count,
+    int flip, uint16_t indir_level, uint16_t *name_count,
     int *printed_something, int *need_separator, int *returnval)
 {
        uint32_t magindex = 0;
@@ -179,7 +178,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
 
                /* if main entry matches, print it... */
                switch (mget(ms, s, m, nbytes, offset, cont_level, mode, text,
-                   flip, indir_level, name_level, name_count,
+                   flip, indir_level, name_count,
                    printed_something, need_separator, returnval)) {
                case -1:
                        return -1;
@@ -268,7 +267,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
                        }
 #endif
                        switch (mget(ms, s, m, nbytes, offset, cont_level, mode,
-                           text, flip, indir_level, name_level, name_count,
+                           text, flip, indir_level, name_count,
                            printed_something, need_separator, returnval)) {
                        case -1:
                                return -1;
@@ -1222,7 +1221,7 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
 private int
 mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
     size_t nbytes, size_t o, unsigned int cont_level, int mode, int text,
-    int flip, uint16_t indir_level, uint16_t name_level, uint16_t *name_count,
+    int flip, uint16_t indir_level, uint16_t *name_count,
     int *printed_something, int *need_separator, int *returnval)
 {
        uint32_t offset = ms->offset;
@@ -1233,18 +1232,12 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
        union VALUETYPE *p = &ms->ms_value;
        struct mlist ml;
 
-       if (indir_level >= ms->indir_recursion) {
+       if (indir_level >= ms->indir_max) {
                file_error(ms, 0, "indirect recursion nesting (%hu) exceeded",
                    indir_level);
                return -1;
        }
 
-       if (name_level >= ms->name_recursion) {
-               file_error(ms, 0, "name recursion nesting (%hu) exceeded",
-                   name_level);
-               return -1;
-       }
-
        if (*name_count >= ms->name_max) {
                file_error(ms, 0, "name use count (%hu) exceeded",
                    *name_count);
@@ -1258,9 +1251,9 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
        if ((ms->flags & MAGIC_DEBUG) != 0) {
                fprintf(stderr, "mget(type=%d, flag=%x, offset=%u, o=%"
                    SIZE_T_FORMAT "u, " "nbytes=%" SIZE_T_FORMAT
-                   "u, il=%hu, nl=%hu nc=%hu)\n",
+                   "u, il=%hu, nc=%hu)\n",
                    m->type, m->flag, offset, o, nbytes,
-                   indir_level, name_level, *name_count);
+                   indir_level, *name_count);
                mdebug(offset, (char *)(void *)p, sizeof(union VALUETYPE));
 #ifndef COMPILE_ONLY
                file_mdump(m);
@@ -1701,7 +1694,7 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
                        return -1;
 
                rv = file_softmagic(ms, s + offset, nbytes - offset,
-                   indir_level + 1, name_level, name_count, BINTEST, text);
+                   indir_level + 1, name_count, BINTEST, text);
 
                if ((ms->flags & MAGIC_DEBUG) != 0)
                        fprintf(stderr, "indirect @offs=%u[%d]\n", offset, rv);
@@ -1741,7 +1734,7 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
                if (m->flag & NOSPACE)
                        *need_separator = 0;
                rv = match(ms, ml.magic, ml.nmagic, s, nbytes, offset + o,
-                   mode, text, flip, indir_level, name_level + 1, name_count,
+                   mode, text, flip, indir_level, name_count,
                    printed_something, need_separator, returnval);
                if (rv != 1)
                    *need_separator = oneed_separator;