Lines Matching refs:ms

127 private int getvalue(struct magic_set *ms, struct magic *, const char **, int);
412 apprentice_1(struct magic_set *ms, const char *fn, int action) in apprentice_1() argument
419 file_error(ms, 0, "magic element size %lu != %lu", in apprentice_1()
426 map = apprentice_load(ms, fn, action); in apprentice_1()
429 return apprentice_compile(ms, map, fn); in apprentice_1()
432 map = apprentice_map(ms, fn); in apprentice_1()
437 if (ms->flags & MAGIC_CHECK) in apprentice_1()
438 file_magwarn(ms, "using regular magic file `%s'", fn); in apprentice_1()
439 map = apprentice_load(ms, fn, action); in apprentice_1()
446 if (add_mlist(ms->mlist[i], map, i) == -1) { in apprentice_1()
447 file_oomem(ms, sizeof(*ml)); in apprentice_1()
456 apprentice_list(ms->mlist[i], BINTEST); in apprentice_1()
458 apprentice_list(ms->mlist[i], TEXTTEST); in apprentice_1()
465 file_ms_free(struct magic_set *ms) in file_ms_free() argument
468 if (ms == NULL) in file_ms_free()
471 mlist_free(ms->mlist[i]); in file_ms_free()
472 if (ms->o.pbuf) { in file_ms_free()
473 efree(ms->o.pbuf); in file_ms_free()
475 if (ms->o.buf) { in file_ms_free()
476 efree(ms->o.buf); in file_ms_free()
478 if (ms->c.li) { in file_ms_free()
479 efree(ms->c.li); in file_ms_free()
481 efree(ms); in file_ms_free()
487 struct magic_set *ms; in file_ms_alloc() local
490 if ((ms = CAST(struct magic_set *, ecalloc((size_t)1, in file_ms_alloc()
494 if (magic_setflags(ms, flags) == -1) { in file_ms_alloc()
499 ms->o.buf = ms->o.pbuf = NULL; in file_ms_alloc()
500 len = (ms->c.len = 10) * sizeof(*ms->c.li); in file_ms_alloc()
502 if ((ms->c.li = CAST(struct level_info *, emalloc(len))) == NULL) in file_ms_alloc()
505 ms->event_flags = 0; in file_ms_alloc()
506 ms->error = -1; in file_ms_alloc()
508 ms->mlist[i] = NULL; in file_ms_alloc()
509 ms->file = "unknown"; in file_ms_alloc()
510 ms->line = 0; in file_ms_alloc()
511 ms->indir_max = FILE_INDIR_MAX; in file_ms_alloc()
512 ms->name_max = FILE_NAME_MAX; in file_ms_alloc()
513 ms->elf_shnum_max = FILE_ELF_SHNUM_MAX; in file_ms_alloc()
514 ms->elf_phnum_max = FILE_ELF_PHNUM_MAX; in file_ms_alloc()
515 ms->elf_notes_max = FILE_ELF_NOTES_MAX; in file_ms_alloc()
516 ms->regex_max = FILE_REGEX_MAX; in file_ms_alloc()
517 ms->bytes_max = FILE_BYTES_MAX; in file_ms_alloc()
518 return ms; in file_ms_alloc()
520 efree(ms); in file_ms_alloc()
575 file_apprentice(struct magic_set *ms, const char *fn, int action) in file_apprentice() argument
581 if (ms->mlist[0] != NULL) in file_apprentice()
582 file_reset(ms); in file_apprentice()
596 mlist_free(ms->mlist[i]); in file_apprentice()
597 if ((ms->mlist[i] = mlist_alloc()) == NULL) { in file_apprentice()
598 file_oomem(ms, sizeof(*ms->mlist[i])); in file_apprentice()
602 return apprentice_1(ms, fn, action); in file_apprentice()
606 file_oomem(ms, strlen(fn)); in file_apprentice()
611 mlist_free(ms->mlist[i]); in file_apprentice()
612 if ((ms->mlist[i] = mlist_alloc()) == NULL) { in file_apprentice()
613 file_oomem(ms, sizeof(*ms->mlist[i])); in file_apprentice()
615 mlist_free(ms->mlist[i]); in file_apprentice()
616 ms->mlist[i] = NULL; in file_apprentice()
630 file_err = apprentice_1(ms, fn, action); in file_apprentice()
639 mlist_free(ms->mlist[i]); in file_apprentice()
640 ms->mlist[i] = NULL; in file_apprentice()
642 file_error(ms, 0, "could not find any valid magic files!"); in file_apprentice()
654 mlist_free(ms->mlist[i]); in file_apprentice()
655 ms->mlist[i] = NULL; in file_apprentice()
666 file_error(ms, 0, "Invalid action %d", action); in file_apprentice()
1010 addentry(struct magic_set *ms, struct magic_entry *me, in addentry() argument
1021 file_oomem(ms, sizeof(*mp) * mset[i].max); in addentry()
1037 load_1(struct magic_set *ms, int action, const char *fn, int *errs, in load_1() argument
1049 ms->file = fn; in load_1()
1054 file_error(ms, errno, "cannot read magic file `%s'", in load_1()
1062 …for (ms->line = 1; (line = php_stream_get_line(stream, buffer , BUFSIZ, &len)) != NULL; ms->line++… in load_1()
1084 file_error(ms, 0, in load_1()
1090 file_error(ms, 0, in load_1()
1096 if ((*bang[i].fun)(ms, &me, in load_1()
1106 switch (parse(ms, &me, line, lineno, action)) { in load_1()
1110 (void)addentry(ms, &me, mset); in load_1()
1119 (void)addentry(ms, &me, mset); in load_1()
1136 set_text_binary(struct magic_set *ms, struct magic_entry *me, uint32_t nme, in set_text_binary() argument
1147 if ((ms->flags & MAGIC_DEBUG) == 0) in set_text_binary()
1169 set_last_default(struct magic_set *ms, struct magic_entry *me, uint32_t nme) in set_last_default() argument
1180 ms->line = me[i].mp->lineno; in set_last_default()
1181 file_magwarn(ms, in set_last_default()
1190 coalesce_entries(struct magic_set *ms, struct magic_entry *me, uint32_t nme, in coalesce_entries() argument
1201 file_oomem(ms, slen); in coalesce_entries()
1227 apprentice_load(struct magic_set *ms, const char *fn, int action) in apprentice_load() argument
1241 ms->flags |= MAGIC_CHECK; /* Enable checks for parsed files */ in apprentice_load()
1246 file_oomem(ms, sizeof(*map)); in apprentice_load()
1269 file_oomem(ms, in apprentice_load()
1284 file_oomem(ms, mlen); in apprentice_load()
1295 load_1(ms, action, filearr[i], &errs, mset); in apprentice_load()
1300 load_1(ms, action, fn, &errs, mset); in apprentice_load()
1311 i = set_text_binary(ms, mset[j].me, mset[j].count, i); in apprentice_load()
1321 set_last_default(ms, mset[j].me, mset[j].count); in apprentice_load()
1324 if (coalesce_entries(ms, mset[j].me, mset[j].count, in apprentice_load()
1346 file_signextend(struct magic_set *ms, struct magic *m, uint64_t v) in file_signextend() argument
1411 if (ms->flags & MAGIC_CHECK) in file_signextend()
1412 file_magwarn(ms, "cannot happen: m->type=%d\n", in file_signextend()
1421 string_modifier_check(struct magic_set *ms, struct magic *m) in string_modifier_check() argument
1423 if ((ms->flags & MAGIC_CHECK) == 0) in string_modifier_check()
1428 file_magwarn(ms, in string_modifier_check()
1436 file_magwarn(ms, in string_modifier_check()
1444 file_magwarn(ms, in string_modifier_check()
1452 file_magwarn(ms, in string_modifier_check()
1461 file_magwarn(ms, "'/%c' not allowed on regex\n", in string_modifier_check()
1466 file_magwarn(ms, "'/%c' not allowed on regex\n", in string_modifier_check()
1472 file_magwarn(ms, "coding error: m->type=%d\n", in string_modifier_check()
1532 check_cond(struct magic_set *ms, int cond, uint32_t cont_level) in check_cond() argument
1535 last_cond = ms->c.li[cont_level].last_cond; in check_cond()
1540 if (ms->flags & MAGIC_CHECK) in check_cond()
1541 file_magwarn(ms, "syntax error: `if'"); in check_cond()
1549 if (ms->flags & MAGIC_CHECK) in check_cond()
1550 file_magwarn(ms, "syntax error: `elif'"); in check_cond()
1558 if (ms->flags & MAGIC_CHECK) in check_cond()
1559 file_magwarn(ms, "syntax error: `else'"); in check_cond()
1570 ms->c.li[cont_level].last_cond = last_cond; in check_cond()
1576 parse_indirect_modifier(struct magic_set *ms, struct magic *m, const char **lp) in parse_indirect_modifier() argument
1586 if (ms->flags & MAGIC_CHECK) in parse_indirect_modifier()
1587 file_magwarn(ms, "indirect modifier `%c' " in parse_indirect_modifier()
1597 parse_op_modifier(struct magic_set *ms, struct magic *m, const char **lp, in parse_op_modifier() argument
1608 m->num_mask = file_signextend(ms, m, val); in parse_op_modifier()
1614 parse_string_modifier(struct magic_set *ms, struct magic *m, const char **lp) in parse_string_modifier() argument
1626 if (have_range && (ms->flags & MAGIC_CHECK)) in parse_string_modifier()
1627 file_magwarn(ms, "multiple ranges"); in parse_string_modifier()
1631 file_magwarn(ms, "zero range"); in parse_string_modifier()
1696 if (ms->flags & MAGIC_CHECK) in parse_string_modifier()
1697 file_magwarn(ms, "string modifier `%c' " in parse_string_modifier()
1705 if (string_modifier_check(ms, m) == -1) in parse_string_modifier()
1718 parse(struct magic_set *ms, struct magic_entry *me, const char *line, in parse() argument
1743 if (file_check_mem(ms, cont_level) == -1) in parse()
1749 file_magerror(ms, "No current entry for continuation"); in parse()
1753 file_magerror(ms, "Continuations present with 0 count"); in parse()
1759 file_magwarn(ms, "New continuation level %u is more " in parse()
1767 file_oomem(ms, sizeof(*nm) * cnt); in parse()
1781 file_oomem(ms, len); in parse()
1810 if (ms->flags & MAGIC_CHECK) in parse()
1811 file_magwarn(ms, "relative offset at level 0"); in parse()
1818 if (ms->flags & MAGIC_CHECK) in parse()
1819 file_magwarn(ms, "offset `%s' invalid", l); in parse()
1876 if (ms->flags & MAGIC_CHECK) in parse()
1877 file_magwarn(ms, in parse()
1900 if (ms->flags & MAGIC_CHECK) in parse()
1901 file_magwarn(ms, in parse()
1909 if (ms->flags & MAGIC_CHECK) in parse()
1910 file_magwarn(ms, in parse()
1919 if (check_cond(ms, m->cond, cont_level) == -1) in parse()
1974 if (ms->flags & MAGIC_CHECK) in parse()
1975 file_magwarn(ms, "type `%s' invalid", l); in parse()
1986 else if (ms->flags & MAGIC_CHECK) in parse()
1987 file_magwarn(ms, "'~' invalid for string types"); in parse()
1997 if (ms->flags & MAGIC_CHECK) in parse()
1998 file_magwarn(ms, in parse()
2005 r = parse_indirect_modifier(ms, m, &l); in parse()
2007 r = parse_string_modifier(ms, m, &l); in parse()
2011 parse_op_modifier(ms, m, &l, op); in parse()
2026 if (ms->flags & MAGIC_CHECK) { in parse()
2027 file_magwarn(ms, "%c= not supported", in parse()
2061 if (m->reln != 'x' && getvalue(ms, m, &l, action)) in parse()
2086 if (ms->flags & MAGIC_CHECK) in parse()
2087 file_magwarn(ms, "description `%s' truncated", m->desc); in parse()
2094 if (ms->flags & MAGIC_CHECK) { in parse()
2095 if (check_format(ms, m) == -1) in parse()
2107 parse_strength(struct magic_set *ms, struct magic_entry *me, const char *line) in parse_strength() argument
2115 file_magwarn(ms, in parse_strength()
2121 file_magwarn(ms, "%s: Strength setting is not supported in " in parse_strength()
2135 file_magwarn(ms, "Unknown factor op `%c'", *l); in parse_strength()
2141 file_magwarn(ms, "Too large factor `%lu'", factor); in parse_strength()
2145 file_magwarn(ms, "Bad factor `%s'", l); in parse_strength()
2150 file_magwarn(ms, "Cannot have factor op `%c' and factor %u", in parse_strength()
2168 parse_extra(struct magic_set *ms, struct magic_entry *me, const char *line, in parse_extra() argument
2178 file_magwarn(ms, "Current entry already has a %s type " in parse_extra()
2184 file_magwarn(ms, "Current entry does not yet have a " in parse_extra()
2196 if (ms->flags & MAGIC_CHECK) in parse_extra()
2197 file_magwarn(ms, "%s type `%s' truncated %" in parse_extra()
2201 file_magwarn(ms, "%s type `%s' has bad char '%c'", in parse_extra()
2210 file_magerror(ms, "Bad magic entry '%s'", line); in parse_extra()
2219 parse_apple(struct magic_set *ms, struct magic_entry *me, const char *line) in parse_apple() argument
2223 return parse_extra(ms, me, line, in parse_apple()
2232 parse_ext(struct magic_set *ms, struct magic_entry *me, const char *line) in parse_ext() argument
2236 return parse_extra(ms, me, line, in parse_ext()
2246 parse_mime(struct magic_set *ms, struct magic_entry *me, const char *line) in parse_mime() argument
2250 return parse_extra(ms, me, line, in parse_mime()
2451 check_format(struct magic_set *ms, struct magic *m) in check_format() argument
2467 file_magwarn(ms, "Internal error inconsistency between " in check_format()
2472 file_magwarn(ms, "No format string for `%s' with description " in check_format()
2483 file_magwarn(ms, "Printf format is %s for type " in check_format()
2491 file_magwarn(ms, in check_format()
2507 getvalue(struct magic_set *ms, struct magic *m, const char **p, int action) in getvalue() argument
2519 *p = getstr(ms, m, *p, action == FILE_COMPILE); in getvalue()
2521 if (ms->flags & MAGIC_CHECK) in getvalue()
2522 file_magwarn(ms, "cannot get string from `%s'", in getvalue()
2572 m->value.q = file_signextend(ms, m, in getvalue()
2590 getstr(struct magic_set *ms, struct magic *m, const char *s, int warn) in getstr() argument
2604 file_error(ms, 0, "string too long: `%s'", origs); in getstr()
2612 file_magwarn(ms, "incomplete escape"); in getstr()
2618 file_magwarn(ms, in getstr()
2632 file_magwarn(ms, "no " in getstr()
2637 file_magwarn(ms, in getstr()
2853 apprentice_buf(struct magic_set *ms, struct magic *buf, size_t len) in apprentice_buf() argument
2858 file_oomem(ms, sizeof(*map)); in apprentice_buf()
2864 if (check_buffer(ms, map, "buffer") != 0) { in apprentice_buf()
2876 apprentice_map(struct magic_set *ms, const char *fn) in apprentice_map() argument
2890 file_oomem(ms, sizeof(*map)); in apprentice_map()
2909 dbname = mkdbname(ms, fn, 0); in apprentice_map()
2920 file_error(ms, errno, "cannot stat `%s'", dbname); in apprentice_map()
2924 file_error(ms, 0, "file `%s' is too %s", dbname, in apprentice_map()
2931 file_oomem(ms, map->len); in apprentice_map()
2935 file_badread(ms); in apprentice_map()
2948 file_error(ms, 0, "bad magic in `%s'", dbname); in apprentice_map()
2959 file_error(ms, 0, "File %d.%d supports only version %d magic " in apprentice_map()
2977 file_error(ms, 0, "Size of `%s' %llu is not a multiple of %zu", in apprentice_map()
2995 file_error(ms, 0, "Inconsistent entries in `%s' %u != %u", in apprentice_map()
3020 check_buffer(struct magic_set *ms, struct magic_map *map, const char *dbname) in check_buffer() argument
3030 file_error(ms, 0, "bad magic in `%s'", dbname); in check_buffer()
3041 file_error(ms, 0, "File %s supports only version %d magic " in check_buffer()
3048 file_error(ms, 0, "Size of `%s' %" SIZE_T_FORMAT "u is not " in check_buffer()
3065 file_error(ms, 0, "Inconsistent entries in `%s' %u != %u", in check_buffer()
3079 apprentice_compile(struct magic_set *ms, struct magic_map *map, const char *fn) in apprentice_compile() argument
3093 dbname = mkdbname(ms, fn, 1); in apprentice_compile()
3102 file_error(ms, errno, "cannot open `%s'", dbname); in apprentice_compile()
3111 file_error(ms, errno, "error writing `%s'", dbname); in apprentice_compile()
3118 file_error(ms, errno, "error writing `%s'", dbname); in apprentice_compile()
3137 mkdbname(struct magic_set *ms, const char *fn, int strip) argument
3161 if (ms->flags & MAGIC_MIME) {
3168 ms->flags &= MAGIC_MIME_TYPE;
3177 ms->flags &= MAGIC_MIME_TYPE;
3336 file_magicfind(struct magic_set *ms, const char *name, struct mlist *v) argument
3341 mlist = ms->mlist[1];