Lines Matching refs:ms
130 private int getvalue(struct magic_set *ms, struct magic *, const char **, int);
425 apprentice_1(struct magic_set *ms, const char *fn, int action) in apprentice_1() argument
434 file_error(ms, 0, "magic element size %lu != %lu", in apprentice_1()
441 map = apprentice_load(ms, fn, action); in apprentice_1()
444 return apprentice_compile(ms, map, fn); in apprentice_1()
448 map = apprentice_map(ms, fn); in apprentice_1()
450 if (ms->flags & MAGIC_CHECK) in apprentice_1()
451 file_magwarn(ms, "using regular magic file `%s'", fn); in apprentice_1()
452 map = apprentice_load(ms, fn, action); in apprentice_1()
458 if (add_mlist(ms->mlist[i], map, i) == -1) { in apprentice_1()
463 mlist_free_all(ms); in apprentice_1()
464 file_oomem(ms, sizeof(*ml)); in apprentice_1()
473 apprentice_list(ms->mlist[i], BINTEST); in apprentice_1()
475 apprentice_list(ms->mlist[i], TEXTTEST); in apprentice_1()
485 file_ms_free(struct magic_set *ms) in file_ms_free() argument
488 if (ms == NULL) in file_ms_free()
491 mlist_free(ms->mlist[i]); in file_ms_free()
492 if (ms->o.pbuf) { in file_ms_free()
493 efree(ms->o.pbuf); in file_ms_free()
495 if (ms->o.buf) { in file_ms_free()
496 efree(ms->o.buf); in file_ms_free()
498 if (ms->c.li) { in file_ms_free()
499 efree(ms->c.li); in file_ms_free()
501 efree(ms); in file_ms_free()
507 struct magic_set *ms; in file_ms_alloc() local
510 if ((ms = CAST(struct magic_set *, ecalloc(CAST(size_t, 1u), in file_ms_alloc()
514 if (magic_setflags(ms, flags) == -1) { in file_ms_alloc()
519 ms->o.buf = ms->o.pbuf = NULL; in file_ms_alloc()
520 ms->o.blen = 0; in file_ms_alloc()
521 len = (ms->c.len = 10) * sizeof(*ms->c.li); in file_ms_alloc()
523 if ((ms->c.li = CAST(struct level_info *, emalloc(len))) == NULL) in file_ms_alloc()
526 ms->event_flags = 0; in file_ms_alloc()
527 ms->error = -1; in file_ms_alloc()
529 ms->mlist[i] = NULL; in file_ms_alloc()
530 ms->file = "unknown"; in file_ms_alloc()
531 ms->line = 0; in file_ms_alloc()
532 ms->indir_max = FILE_INDIR_MAX; in file_ms_alloc()
533 ms->name_max = FILE_NAME_MAX; in file_ms_alloc()
534 ms->elf_shnum_max = FILE_ELF_SHNUM_MAX; in file_ms_alloc()
535 ms->elf_phnum_max = FILE_ELF_PHNUM_MAX; in file_ms_alloc()
536 ms->elf_notes_max = FILE_ELF_NOTES_MAX; in file_ms_alloc()
537 ms->regex_max = FILE_REGEX_MAX; in file_ms_alloc()
538 ms->bytes_max = FILE_BYTES_MAX; in file_ms_alloc()
539 return ms; in file_ms_alloc()
541 efree(ms); in file_ms_alloc()
577 mlist_free_all(struct magic_set *ms) in mlist_free_all() argument
582 mlist_free(ms->mlist[i]); in mlist_free_all()
583 ms->mlist[i] = NULL; in mlist_free_all()
613 file_apprentice(struct magic_set *ms, const char *fn, int action) in file_apprentice() argument
619 (void)file_reset(ms, 0); in file_apprentice()
633 mlist_free(ms->mlist[i]); in file_apprentice()
634 if ((ms->mlist[i] = mlist_alloc()) == NULL) { in file_apprentice()
635 file_oomem(ms, sizeof(*ms->mlist[i])); in file_apprentice()
639 return apprentice_1(ms, fn, action); in file_apprentice()
643 file_oomem(ms, strlen(fn)); in file_apprentice()
648 mlist_free(ms->mlist[i]); in file_apprentice()
649 if ((ms->mlist[i] = mlist_alloc()) == NULL) { in file_apprentice()
650 file_oomem(ms, sizeof(*ms->mlist[i])); in file_apprentice()
652 mlist_free(ms->mlist[j]); in file_apprentice()
653 ms->mlist[j] = NULL; in file_apprentice()
667 fileerr = apprentice_1(ms, fn, action); in file_apprentice()
676 mlist_free(ms->mlist[i]); in file_apprentice()
677 ms->mlist[i] = NULL; in file_apprentice()
679 file_error(ms, 0, "could not find any valid magic files!"); in file_apprentice()
691 mlist_free(ms->mlist[i]); in file_apprentice()
692 ms->mlist[i] = NULL; in file_apprentice()
703 file_error(ms, 0, "Invalid action %d", action); in file_apprentice()
1103 addentry(struct magic_set *ms, struct magic_entry *me, in addentry() argument
1114 file_oomem(ms, sizeof(*mp) * mset[i].max); in addentry()
1130 load_1(struct magic_set *ms, int action, const char *fn, int *errs, in load_1() argument
1142 ms->file = fn; in load_1()
1147 file_error(ms, errno, "cannot read magic file `%s'", in load_1()
1155 …for (ms->line = 1; (line = php_stream_get_line(stream, buffer , BUFSIZ, &len)) != NULL; ms->line++… in load_1()
1177 file_error(ms, 0, in load_1()
1183 file_error(ms, 0, in load_1()
1189 if ((*bang[i].fun)(ms, &me, in load_1()
1200 switch (parse(ms, &me, line, lineno, action)) { in load_1()
1204 (void)addentry(ms, &me, mset); in load_1()
1213 (void)addentry(ms, &me, mset); in load_1()
1230 set_text_binary(struct magic_set *ms, struct magic_entry *me, uint32_t nme, in set_text_binary() argument
1241 if ((ms->flags & MAGIC_DEBUG) == 0) in set_text_binary()
1263 set_last_default(struct magic_set *ms, struct magic_entry *me, uint32_t nme) in set_last_default() argument
1274 ms->line = me[i].mp->lineno; in set_last_default()
1275 file_magwarn(ms, in set_last_default()
1284 coalesce_entries(struct magic_set *ms, struct magic_entry *me, uint32_t nme, in coalesce_entries() argument
1295 file_oomem(ms, slen); in coalesce_entries()
1321 apprentice_load(struct magic_set *ms, const char *fn, int action) in apprentice_load() argument
1335 ms->flags |= MAGIC_CHECK; /* Enable checks for parsed files */ in apprentice_load()
1340 file_oomem(ms, sizeof(*map)); in apprentice_load()
1363 file_oomem(ms, in apprentice_load()
1378 file_oomem(ms, mlen); in apprentice_load()
1390 load_1(ms, action, filearr[i], &errs, mset); in apprentice_load()
1396 load_1(ms, action, fn, &errs, mset); in apprentice_load()
1407 i = set_text_binary(ms, mset[j].me, mset[j].count, i); in apprentice_load()
1417 set_last_default(ms, mset[j].me, mset[j].count); in apprentice_load()
1420 if (coalesce_entries(ms, mset[j].me, mset[j].count, in apprentice_load()
1442 file_signextend(struct magic_set *ms, struct magic *m, uint64_t v) in file_signextend() argument
1509 if (ms->flags & MAGIC_CHECK) in file_signextend()
1510 file_magwarn(ms, "cannot happen: m->type=%d\n", in file_signextend()
1519 string_modifier_check(struct magic_set *ms, struct magic *m) in string_modifier_check() argument
1521 if ((ms->flags & MAGIC_CHECK) == 0) in string_modifier_check()
1526 file_magwarn(ms, in string_modifier_check()
1534 file_magwarn(ms, in string_modifier_check()
1542 file_magwarn(ms, in string_modifier_check()
1550 file_magwarn(ms, in string_modifier_check()
1559 file_magwarn(ms, "'/%c' not allowed on regex\n", in string_modifier_check()
1564 file_magwarn(ms, "'/%c' not allowed on regex\n", in string_modifier_check()
1570 file_magwarn(ms, "coding error: m->type=%d\n", in string_modifier_check()
1630 check_cond(struct magic_set *ms, int cond, uint32_t cont_level) in check_cond() argument
1633 last_cond = ms->c.li[cont_level].last_cond; in check_cond()
1638 if (ms->flags & MAGIC_CHECK) in check_cond()
1639 file_magwarn(ms, "syntax error: `if'"); in check_cond()
1647 if (ms->flags & MAGIC_CHECK) in check_cond()
1648 file_magwarn(ms, "syntax error: `elif'"); in check_cond()
1656 if (ms->flags & MAGIC_CHECK) in check_cond()
1657 file_magwarn(ms, "syntax error: `else'"); in check_cond()
1668 ms->c.li[cont_level].last_cond = last_cond; in check_cond()
1674 parse_indirect_modifier(struct magic_set *ms, struct magic *m, const char **lp) in parse_indirect_modifier() argument
1684 if (ms->flags & MAGIC_CHECK) in parse_indirect_modifier()
1685 file_magwarn(ms, "indirect modifier `%c' " in parse_indirect_modifier()
1695 parse_op_modifier(struct magic_set *ms, struct magic *m, const char **lp, in parse_op_modifier() argument
1706 m->num_mask = file_signextend(ms, m, val); in parse_op_modifier()
1712 parse_string_modifier(struct magic_set *ms, struct magic *m, const char **lp) in parse_string_modifier() argument
1724 if (have_range && (ms->flags & MAGIC_CHECK)) in parse_string_modifier()
1725 file_magwarn(ms, "multiple ranges"); in parse_string_modifier()
1729 file_magwarn(ms, "zero range"); in parse_string_modifier()
1794 if (ms->flags & MAGIC_CHECK) in parse_string_modifier()
1795 file_magwarn(ms, "string modifier `%c' " in parse_string_modifier()
1803 if (string_modifier_check(ms, m) == -1) in parse_string_modifier()
1816 parse(struct magic_set *ms, struct magic_entry *me, const char *line, in parse() argument
1841 if (file_check_mem(ms, cont_level) == -1) in parse()
1847 file_magerror(ms, "No current entry for continuation"); in parse()
1851 file_magerror(ms, "Continuations present with 0 count"); in parse()
1857 file_magwarn(ms, "New continuation level %u is more " in parse()
1865 file_oomem(ms, sizeof(*nm) * cnt); in parse()
1879 file_oomem(ms, len); in parse()
1908 if (ms->flags & MAGIC_CHECK) in parse()
1909 file_magwarn(ms, "relative offset at level 0"); in parse()
1920 if (ms->flags & MAGIC_CHECK) in parse()
1921 file_magwarn(ms, "offset `%s' invalid", l); in parse()
1985 if (ms->flags & MAGIC_CHECK) in parse()
1986 file_magwarn(ms, in parse()
2009 if (ms->flags & MAGIC_CHECK) in parse()
2010 file_magwarn(ms, in parse()
2018 if (ms->flags & MAGIC_CHECK) in parse()
2019 file_magwarn(ms, in parse()
2028 if (check_cond(ms, m->cond, cont_level) == -1) in parse()
2084 if (ms->flags & MAGIC_CHECK) in parse()
2085 file_magwarn(ms, "type `%s' invalid", l); in parse()
2096 else if (ms->flags & MAGIC_CHECK) in parse()
2097 file_magwarn(ms, "'~' invalid for string types"); in parse()
2107 if (ms->flags & MAGIC_CHECK) in parse()
2108 file_magwarn(ms, in parse()
2115 r = parse_indirect_modifier(ms, m, &l); in parse()
2117 r = parse_string_modifier(ms, m, &l); in parse()
2121 parse_op_modifier(ms, m, &l, op); in parse()
2136 if (ms->flags & MAGIC_CHECK) { in parse()
2137 file_magwarn(ms, "%c= not supported", in parse()
2171 if (m->reln != 'x' && getvalue(ms, m, &l, action)) in parse()
2196 if (ms->flags & MAGIC_CHECK) in parse()
2197 file_magwarn(ms, "description `%s' truncated", m->desc); in parse()
2204 if (ms->flags & MAGIC_CHECK) { in parse()
2205 if (check_format(ms, m) == -1) in parse()
2222 parse_strength(struct magic_set *ms, struct magic_entry *me, const char *line, in parse_strength() argument
2231 file_magwarn(ms, in parse_strength()
2237 file_magwarn(ms, "%s: Strength setting is not supported in " in parse_strength()
2251 file_magwarn(ms, "Unknown factor op `%c'", *l); in parse_strength()
2257 file_magwarn(ms, "Too large factor `%lu'", factor); in parse_strength()
2261 file_magwarn(ms, "Bad factor `%s'", l); in parse_strength()
2266 file_magwarn(ms, "Cannot have factor op `%c' and factor %u", in parse_strength()
2284 parse_extra(struct magic_set *ms, struct magic_entry *me, const char *line, in parse_extra() argument
2294 file_magwarn(ms, "Current entry already has a %s type " in parse_extra()
2300 file_magwarn(ms, "Current entry does not yet have a " in parse_extra()
2313 if (ms->flags & MAGIC_CHECK) in parse_extra()
2314 file_magwarn(ms, "%s type `%s' truncated %" in parse_extra()
2318 file_magwarn(ms, "%s type `%s' has bad char '%c'", in parse_extra()
2327 file_magerror(ms, "Bad magic entry '%s'", line); in parse_extra()
2336 parse_apple(struct magic_set *ms, struct magic_entry *me, const char *line, in parse_apple() argument
2341 return parse_extra(ms, me, line, len, in parse_apple()
2350 parse_ext(struct magic_set *ms, struct magic_entry *me, const char *line, in parse_ext() argument
2355 return parse_extra(ms, me, line, len, in parse_ext()
2365 parse_mime(struct magic_set *ms, struct magic_entry *me, const char *line, in parse_mime() argument
2370 return parse_extra(ms, me, line, len, in parse_mime()
2571 check_format(struct magic_set *ms, struct magic *m) in check_format() argument
2587 file_magwarn(ms, "Internal error inconsistency between " in check_format()
2592 file_magwarn(ms, "No format string for `%s' with description " in check_format()
2603 file_magwarn(ms, "Printf format is %s for type " in check_format()
2611 file_magwarn(ms, in check_format()
2627 getvalue(struct magic_set *ms, struct magic *m, const char **p, int action) in getvalue() argument
2642 *p = getstr(ms, m, *p, action == FILE_COMPILE); in getvalue()
2644 if (ms->flags & MAGIC_CHECK) in getvalue()
2645 file_magwarn(ms, "cannot get string from `%s'", in getvalue()
2700 m->value.q = file_signextend(ms, m, ull); in getvalue()
2702 file_magwarn(ms, "Unparseable number `%s'", *p); in getvalue()
2709 file_magwarn(ms, in getvalue()
2734 file_magwarn(ms, "Overflow for numeric" in getvalue()
2754 getstr(struct magic_set *ms, struct magic *m, const char *s, int warn) in getstr() argument
2768 file_error(ms, 0, "string too long: `%s'", origs); in getstr()
2776 file_magwarn(ms, "incomplete escape"); in getstr()
2782 file_magwarn(ms, in getstr()
2796 file_magwarn(ms, "no " in getstr()
2801 file_magwarn(ms, in getstr()
2906 size_t l = file_pstring_length_size(ms, m); in getstr()
3022 apprentice_map(struct magic_set *ms, const char *fn) in apprentice_map() argument
3036 file_oomem(ms, sizeof(*map)); in apprentice_map()
3055 dbname = mkdbname(ms, fn, 0); in apprentice_map()
3067 file_error(ms, errno, "cannot stat `%s'", dbname); in apprentice_map()
3072 file_error(ms, 0, "file `%s' is too %s", dbname, in apprentice_map()
3082 file_badread(ms); in apprentice_map()
3093 file_error(ms, 0, "bad magic in `%s'", dbname); in apprentice_map()
3104 file_error(ms, 0, "File %d.%d supports only version %d magic " in apprentice_map()
3122 file_error(ms, 0, "Size of `%s' %llu is not a multiple of %zu", in apprentice_map()
3140 file_error(ms, 0, "Inconsistent entries in `%s' %u != %u", in apprentice_map()
3168 apprentice_compile(struct magic_set *ms, struct magic_map *map, const char *fn) in apprentice_compile() argument
3182 dbname = mkdbname(ms, fn, 1); in apprentice_compile()
3191 file_error(ms, errno, "cannot open `%s'", dbname); in apprentice_compile()
3200 file_error(ms, errno, "error writing `%s'", dbname); in apprentice_compile()
3207 file_error(ms, errno, "error writing `%s'", dbname); in apprentice_compile()
3226 mkdbname(struct magic_set *ms, const char *fn, int strip) argument
3250 if (ms->flags & MAGIC_MIME) {
3257 ms->flags &= MAGIC_MIME_TYPE;
3266 ms->flags &= MAGIC_MIME_TYPE;
3363 file_pstring_length_size(struct magic_set *ms, const struct magic *m) argument
3375 file_error(ms, 0, "corrupt magic file "
3382 file_pstring_get_length(struct magic_set *ms, const struct magic *m, argument
3418 file_error(ms, 0, "corrupt magic file "
3425 size_t l = file_pstring_length_size(ms, m);
3435 file_magicfind(struct magic_set *ms, const char *name, struct mlist *v) argument
3440 mlist = ms->mlist[1];