diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/apprentice.c | 32 | ||||
-rw-r--r-- | src/file.h | 5 | ||||
-rw-r--r-- | src/magic.c | 3 | ||||
-rw-r--r-- | src/print.c | 6 | ||||
-rw-r--r-- | src/softmagic.c | 12 |
5 files changed, 33 insertions, 25 deletions
diff --git a/src/apprentice.c b/src/apprentice.c index d0734a57..0d65d844 100644 --- a/src/apprentice.c +++ b/src/apprentice.c @@ -47,7 +47,7 @@ #endif #ifndef lint -FILE_RCSID("@(#)$File: apprentice.c,v 1.116 2008/02/12 01:08:39 rrt Exp $") +FILE_RCSID("@(#)$File: apprentice.c,v 1.117 2008/02/17 19:28:54 rrt Exp $") #endif /* lint */ #define EATAB {while (isascii((unsigned char) *l) && \ @@ -697,7 +697,7 @@ file_signextend(struct magic_set *ms, struct magic *m, uint64_t v) } private int -string_modifier_check(struct magic_set *ms, struct magic const *m) +string_modifier_check(struct magic_set *ms, struct magic *m) { if ((ms->flags & MAGIC_CHECK) == 0) return 0; @@ -721,6 +721,13 @@ string_modifier_check(struct magic_set *ms, struct magic const *m) } break; case FILE_SEARCH: + if (m->str_range == 0) { + file_magwarn(ms, + "missing range; defaulting to %d\n", + STRING_DEFAULT_RANGE); + m->str_range = STRING_DEFAULT_RANGE; + return -1; + } break; case FILE_REGEX: if ((m->str_flags & STRING_COMPACT_BLANK) != 0) { @@ -1060,7 +1067,7 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp, file_magwarn(ms, "'~' invalid for string types"); ++l; } - m->str_count = 0; + m->str_range = 0; m->str_flags = 0; m->num_mask = 0; if ((op = get_op(*l)) != -1) { @@ -1074,23 +1081,24 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp, eatsize(&l); } else if (op == FILE_OPDIVIDE) { - int have_count = 0; + int have_range = 0; while (!isspace((unsigned char)*++l)) { switch (*l) { - /* for portability avoid "case '0' ... '9':" */ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': - case '9': { - if (have_count && + case '9': + if (have_range && (ms->flags & MAGIC_CHECK)) file_magwarn(ms, - "multiple counts"); - have_count = 1; - m->str_count = strtoul(l, &t, 0); + "multiple ranges"); + have_range = 1; + m->str_range = strtoul(l, &t, 0); + if (m->str_range == 0) + file_magwarn(ms, + "zero range"); l = t - 1; break; - } case CHAR_COMPACT_BLANK: m->str_flags |= STRING_COMPACT_BLANK; break; @@ -1985,7 +1993,7 @@ bs1(struct magic *m) m->in_offset = swap4((uint32_t)m->in_offset); m->lineno = swap4((uint32_t)m->lineno); if (IS_STRING(m->type)) { - m->str_count = swap4(m->str_count); + m->str_range = swap4(m->str_range); m->str_flags = swap4(m->str_flags); } else { @@ -27,7 +27,7 @@ */ /* * file.h - definitions for file(1) program - * @(#)$File: file.h,v 1.95 2008/02/12 16:30:48 rrt Exp $ + * @(#)$File: file.h,v 1.96 2008/02/17 19:28:54 rrt Exp $ */ #ifndef __file_h__ @@ -219,7 +219,7 @@ struct magic { } _s; /* for use with string types */ } _u; #define num_mask _u._mask -#define str_count _u._s._count +#define str_range _u._s._count #define str_flags _u._s._flags /* Words 9-16 */ @@ -253,6 +253,7 @@ struct magic { #define CHAR_IGNORE_UPPERCASE 'C' #define CHAR_REGEX_OFFSET_START 's' #define STRING_IGNORE_CASE (STRING_IGNORE_LOWERCASE|STRING_IGNORE_UPPERCASE) +#define STRING_DEFAULT_RANGE 100 /* list of magic entries */ diff --git a/src/magic.c b/src/magic.c index 68b0b170..1ecd177c 100644 --- a/src/magic.c +++ b/src/magic.c @@ -63,7 +63,7 @@ #include "patchlevel.h" #ifndef lint -FILE_RCSID("@(#)$File: magic.c,v 1.48 2008/02/07 00:58:52 christos Exp $") +FILE_RCSID("@(#)$File: magic.c,v 1.49 2008/02/17 19:28:54 rrt Exp $") #endif /* lint */ #ifndef PIPE_BUF @@ -312,6 +312,7 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd) (void)strcat(strcpy(tmp, inname), ".exe"); if ((fd = open(tmp, flags)) < 0) { #endif + fprintf(stderr, "couldn't open file\n"); if (info_from_stat(ms, sb.st_mode) == -1) goto done; rv = 0; diff --git a/src/print.c b/src/print.c index fd2a8b84..c41e71ea 100644 --- a/src/print.c +++ b/src/print.c @@ -41,7 +41,7 @@ #include <time.h> #ifndef lint -FILE_RCSID("@(#)$File: print.c,v 1.62 2008/02/04 20:51:17 christos Exp $") +FILE_RCSID("@(#)$File: print.c,v 1.63 2008/02/17 19:28:54 rrt Exp $") #endif /* lint */ #define SZOF(a) (sizeof(a) / sizeof(a[0])) @@ -89,8 +89,8 @@ file_mdump(struct magic *m) if (m->str_flags & REGEX_OFFSET_START) (void) fputc(CHAR_REGEX_OFFSET_START, stderr); } - if (m->str_count) - (void) fprintf(stderr, "/%u", m->str_count); + if (m->str_range) + (void) fprintf(stderr, "/%u", m->str_range); } else { if ((m->mask_op & FILE_OPS_MASK) < SZOF(optyp)) diff --git a/src/softmagic.c b/src/softmagic.c index 5b53f579..55ab23fc 100644 --- a/src/softmagic.c +++ b/src/softmagic.c @@ -38,7 +38,7 @@ #ifndef lint -FILE_RCSID("@(#)$File: softmagic.c,v 1.109 2008/02/12 15:28:39 rrt Exp $") +FILE_RCSID("@(#)$File: softmagic.c,v 1.110 2008/02/17 19:28:54 rrt Exp $") #endif /* lint */ private int match(struct magic_set *, struct magic *, uint32_t, @@ -884,7 +884,7 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m, size_t nbytes, unsigned int cont_level) { uint32_t offset = ms->offset; - uint32_t count = m->str_count; + uint32_t count = m->str_range; union VALUETYPE *p = &ms->ms_value; if (mcopy(ms, p, m->type, m->flag & INDIR, s, offset, nbytes, count) == -1) @@ -1448,10 +1448,8 @@ file_strncmp(const char *s1, const char *s2, size_t len, uint32_t flags) uint64_t v; /* - * What we want here is: - * v = strncmp(m->value.s, p->s, m->vallen); - * but ignoring any nulls. bcmp doesn't give -/+/0 - * and isn't universally available anyway. + * What we want here is v = strncmp(s1, s2, len), + * but ignoring any nulls. */ v = 0; if (0L == flags) { /* normal string: do it fast */ @@ -1653,7 +1651,7 @@ magiccheck(struct magic_set *ms, struct magic *m) v = 0; ms->search.offset = m->offset; - for (idx = 0; m->str_count == 0 || idx < m->str_count; idx++) { + for (idx = 0; m->str_range == 0 || idx < m->str_range; idx++) { if (slen + idx > ms->search.s_len) break; |