magic file).
Rename str_count to str_range for clarity.
Improve exegetical comment in file_strncmp.
#endif
#ifndef lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.115 2008/02/11 22:12:24 rrt Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.116 2008/02/12 01:08:39 rrt Exp $")
#endif /* lint */
#define EATAB {while (isascii((unsigned char) *l) && \
}
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;
}
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) {
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) {
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;
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 {
*/
/*
* file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.94 2008/02/07 00:58:52 christos Exp $
+ * @(#)$File: file.h,v 1.95 2008/02/12 16:30:48 rrt Exp $
*/
#ifndef __file_h__
} _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 */
#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 */
#include "patchlevel.h"
#ifndef lint
-FILE_RCSID("@(#)$File: magic.c,v 1.47 2008/02/04 20:51:17 christos Exp $")
+FILE_RCSID("@(#)$File: magic.c,v 1.48 2008/02/07 00:58:52 christos Exp $")
#endif /* lint */
#ifndef PIPE_BUF
(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;
#include <time.h>
#ifndef lint
-FILE_RCSID("@(#)$File: print.c,v 1.61 2007/12/27 16:35:59 christos Exp $")
+FILE_RCSID("@(#)$File: print.c,v 1.62 2008/02/04 20:51:17 christos Exp $")
#endif /* lint */
#define SZOF(a) (sizeof(a) / sizeof(a[0]))
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))
#ifndef lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.108 2008/02/11 23:20:51 rrt Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.109 2008/02/12 15:28:39 rrt Exp $")
#endif /* lint */
private int match(struct magic_set *, struct magic *, uint32_t,
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)
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 */
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;