Lines Matching refs:ms
61 mlist_free(ms->mlist[i]);
62 - free(ms->o.pbuf);
63 - free(ms->o.buf);
64 - free(ms->c.li);
65 + if (ms->o.pbuf) {
66 + efree(ms->o.pbuf);
68 + if (ms->o.buf) {
69 + efree(ms->o.buf);
71 + if (ms->c.li) {
72 + efree(ms->c.li);
75 freelocale(ms->c_lc_ctype);
77 - free(ms);
78 + efree(ms);
83 struct magic_set *ms;
86 - if ((ms = CAST(struct magic_set *, calloc(CAST(size_t, 1u),
87 + if ((ms = CAST(struct magic_set *, ecalloc(CAST(size_t, 1u),
88 sizeof(*ms)))) == NULL)
92 ms->o.blen = 0;
93 len = (ms->c.len = 10) * sizeof(*ms->c.li);
95 - if ((ms->c.li = CAST(struct level_info *, malloc(len))) == NULL)
96 + if ((ms->c.li = CAST(struct level_info *, emalloc(len))) == NULL)
99 ms->event_flags = 0;
102 return ms;
104 - free(ms);
105 + efree(ms);
193 -buffer_apprentice(struct magic_set *ms, struct magic **bufs,
202 - (void)file_reset(ms, 0);
207 - mlist_free(ms->mlist[i]);
208 - if ((ms->mlist[i] = mlist_alloc()) == NULL) {
209 - file_oomem(ms, sizeof(*ms->mlist[0]));
215 - map = apprentice_buf(ms, bufs[i], sizes[i]);
220 - if (add_mlist(ms->mlist[j], map, j) == -1) {
221 - file_oomem(ms, sizeof(*ms->mlist[0]));
229 - mlist_free_all(ms);
236 file_apprentice(struct magic_set *ms, const char *fn, int action)
239 (void)file_reset(ms, 0);
254 + mlist_free(ms->mlist[i]);
255 + if ((ms->mlist[i] = mlist_alloc()) == NULL) {
256 + file_oomem(ms, sizeof(*ms->mlist[i]));
260 + return apprentice_1(ms, fn, action);
264 file_oomem(ms, strlen(fn));
268 mlist_free(ms->mlist[j]);
269 ms->mlist[j] = NULL;
292 file_oomem(ms, sizeof(*mp) * incr);
295 load_1(struct magic_set *ms, int action, const char *fn, int *errs,
306 - FILE *f = fopen(ms->file = fn, "r");
311 + ms->file = fn;
316 file_error(ms, errno, "cannot read magic file `%s'",
322 - for (ms->line = 1; (len = getline(&line, &llen, f)) != -1;
323 - ms->line++) {
324 + for (ms->line = 1; (line = php_stream_get_line(stream, buffer , BUFSIZ, &len)) != NULL; ms->line+…
331 (void)addentry(ms, &me, mset);
345 file_oomem(ms, slen);
376 ms->flags |= MAGIC_CHECK; /* Enable checks for parsed files */
382 file_oomem(ms, sizeof(*map));
407 file_oomem(ms,
429 file_oomem(ms, mlen);
446 load_1(ms, action, filearr[i], &errs, mset);
455 load_1(ms, action, fn, &errs, mset);
471 file_oomem(ms, sizeof(*nm) * cnt);
479 file_oomem(ms, len);
489 else if (ms->flags & MAGIC_CHECK)
490 file_magwarn(ms, "'~' invalid for string types");
503 parse_extra(struct magic_set *ms, struct magic_entry *me, const char *line,
515 - file_regcomp(ms, &rx, m->value.s, REG_EXTENDED);
542 -apprentice_buf(struct magic_set *ms, struct magic *buf, size_t len)
547 - file_oomem(ms, sizeof(*map));
553 - if (check_buffer(ms, map, "buffer") != 0) {
565 apprentice_map(struct magic_set *ms, const char *fn)
584 file_oomem(ms, sizeof(*map));
605 dbname = mkdbname(ms, fn, 0);
619 file_error(ms, errno, "cannot stat `%s'", dbname);
625 file_error(ms, 0, "file `%s' is too %s", dbname,
636 - file_error(ms, errno, "cannot map `%s'", dbname);
642 - file_oomem(ms, map->len);
646 - file_badread(ms);
655 - if (check_buffer(ms, map, dbname) != 0) {
660 - file_error(ms, errno, "cannot mprotect `%s'", dbname);
662 + file_badread(ms);
679 -check_buffer(struct magic_set *ms, struct magic_map *map, const char *dbname)
693 file_error(ms, 0, "bad magic in `%s'", dbname);
703 - file_error(ms, 0, "File %s supports only version %d magic "
705 + file_error(ms, 0, "File %d supports only version %d magic "
713 - file_error(ms, 0, "Size of `%s' %" SIZE_T_FORMAT "u is not "
730 + file_error(ms, 0, "Size of `%s' %llu is not a multiple of %zu",
744 file_error(ms, 0, "Inconsistent entries in `%s' %u != %u",
790 file_error(ms, errno, "cannot open `%s'", dbname);
799 file_error(ms, errno, "error writing `%s'", dbname);
808 file_error(ms, errno, "error writing `%s'", dbname);
831 if (ms->flags & MAGIC_MIME) {
842 ms->flags &= MAGIC_MIME_TYPE;
875 rv = file_ascmagic_with_encoding(ms, &bb,
889 file_oomem(ms, mlen);
896 - if (file_printf(ms, ", with very long lines (%"
898 + if (file_printf(ms, ", with very long lines (%zu)",
1251 urv = uncompressbuf(fd, ms->bytes_max, i,
1252 (ms->flags & MAGIC_NO_COMPRESS_FORK), buf, &newbuf, &nsz);
1256 prv = format_decompression_error(ms, i, newbuf);
1258 - prv = file_buffer(ms, -1, NULL, name, newbuf,
1259 + prv = file_buffer(ms, NULL, NULL, name, newbuf,
1267 - if (file_buffer(ms, -1, NULL, NULL, buf, nbytes) == -1)
1268 + if (file_buffer(ms, NULL, NULL, NULL, buf, nbytes) == -1)
1270 if (file_pop_buffer(ms, pb) != NULL)
1274 if ((rbuf = file_pop_buffer(ms, pb)) != NULL) {
1275 if (file_printf(ms, "%s", rbuf) == -1) {
1283 if (!mime && file_printf(ms, ")") == -1)
1292 ms->flags |= MAGIC_COMPRESS;
1310 file_badseek(ms);
1351 nbytes = ms->encoding_max;
1357 file_oomem(ms, mlen);
1365 file_oomem(ms, mlen);
1593 -bad_link(struct magic_set *ms, int err, char *buf)
1595 - int mime = ms->flags & MAGIC_MIME;
1597 - file_printf(ms, "inode/symlink")
1601 - if (ms->flags & MAGIC_ERROR) {
1602 - file_error(ms, err,
1606 - if (file_printf(ms, "broken symbolic link to %s", buf) == -1)
1617 handle_mime(struct magic_set *ms, int mime, const char *str)
1622 -file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
1623 +file_fsmagic(struct magic_set *ms, const char *fn, zend_stat_t *sb)
1626 int mime = ms->flags & MAGIC_MIME;
1627 int silent = ms->flags & (MAGIC_APPLE|MAGIC_EXTENSION);
1643 - if ((ms->flags & MAGIC_SYMLINK) == 0)
1680 if (ms->flags & MAGIC_ERROR) {
1687 - if (handle_mime(ms, mime, "directory") == -1)
1690 - } else if (file_printf(ms, "%sdirectory", COMMA) == -1)
1700 - if ((ms->flags & MAGIC_DEVICES) != 0) {
1705 - if (handle_mime(ms, mime, "chardevice") == -1)
1719 + if ((ms->flags & MAGIC_DEVICES) != 0) {
1724 + if (handle_mime(ms, mime, "chardevice") == -1)
1729 if (file_printf(ms, "%scharacter special (%d/%d/%d)",
1733 if (file_printf(ms, "%scharacter special", COMMA) == -1)
1746 - if ((ms->flags & MAGIC_DEVICES) != 0) {
1751 - if (handle_mime(ms, mime, "blockdevice") == -1)
1757 - if (file_printf(ms, "%sblock special (%d/%d/%d)",
1762 - if (file_printf(ms, "%sblock special (%ld/%ld)",
1770 - if (file_printf(ms, "%sblock special", COMMA) == -1)
1780 if((ms->flags & MAGIC_DEVICES) != 0)
1787 if (ms->flags & MAGIC_ERROR) {
1788 - file_error(ms, errno, "unreadable symlink `%s'",
1790 + file_error(ms, errno, "unreadable symlink `%s'", fn);
1794 - if (handle_mime(ms, mime, "symlink") == -1)
1797 - } else if (file_printf(ms,
1813 - return bad_link(ms, errno, buf);
1817 - return bad_link(ms, errno, buf);
1826 - if (ms->flags & MAGIC_ERROR) {
1827 - file_error(ms, 0,
1832 - if (handle_mime(ms, mime,
1836 - } else if (file_printf(ms,
1850 - return bad_link(ms, errno, buf);
1856 - if ((ms->flags & MAGIC_SYMLINK) != 0) {
1858 - ms->flags &= MAGIC_SYMLINK;
1859 - p = magic_file(ms, buf);
1860 - ms->flags |= MAGIC_SYMLINK;
1865 - if (handle_mime(ms, mime, "symlink") == -1)
1868 - } else if (file_printf(ms, "%ssymbolic link to %s",
1882 file_clearbuf(struct magic_set *ms)
1884 - free(ms->o.buf);
1885 + efree(ms->o.buf);
1886 ms->o.buf = NULL;
1887 ms->o.blen = 0;
1891 file_vprintf(struct magic_set *ms, const char *fmt, va_list ap)
1903 - if (len < 0 || (size_t)len > 1024 || len + ms->o.blen > 1024 * 1024) {
1905 + if (len > 1024 || len + ms->o.blen > 1024 * 1024) {
1906 size_t blen = ms->o.blen;
1909 file_clearbuf(ms);
1910 - file_error(ms, 0, "Output buffer space exceeded %d+%"
1911 + file_error(ms, 0, "Output buffer space exceeded %" SIZE_T_FORMAT "u+%"
1916 if (ms->o.buf != NULL) {
1917 - len = asprintf(&newstr, "%s%s", ms->o.buf, buf);
1921 - free(ms->o.buf);
1922 + len = spprintf(&newstr, 0, "%s%s", ms->o.buf, buf);
1924 + efree(ms->o.buf);
1927 ms->o.buf = buf;
1928 ms->o.blen = len;
1931 - file_clearbuf(ms);
1932 - file_error(ms, errno, "vasprintf failed");
1941 -file_buffer(struct magic_set *ms, int fd, struct stat *st,
1942 +file_buffer(struct magic_set *ms, php_stream *stream, zend_stat_t *st,
1965 ms->mode = b.st.st_mode;
1974 if ((ms->flags & MAGIC_NO_CHECK_COMPRESS) == 0) {
1975 m = file_zmagic(ms, &b, inname);
1977 rv = file_tryelf(ms, &b);
1978 rbuf = file_pop_buffer(ms, pb);
1984 if ((ms->flags & MAGIC_DEBUG) != 0)
1986 if (file_printf(ms, "%s", code_mime) == -1)
2000 file_clearbuf(ms);
2001 if (ms->o.pbuf) {
2002 - free(ms->o.pbuf);
2003 + efree(ms->o.pbuf);
2004 ms->o.pbuf = NULL;
2006 ms->event_flags &= ~EVENT_HAD_ERR;
2011 - if ((pbuf = CAST(char *, realloc(ms->o.pbuf, psize))) == NULL) {
2012 + if ((pbuf = CAST(char *, erealloc(ms->o.pbuf, psize))) == NULL) {
2013 file_oomem(ms, psize);
2017 if (level >= ms->c.len) {
2018 len = (ms->c.len = 20 + level) * sizeof(*ms->c.li);
2019 ms->c.li = CAST(struct level_info *, (ms->c.li == NULL) ?
2021 - realloc(ms->c.li, len));
2023 + erealloc(ms->c.li, len));
2024 if (ms->c.li == NULL) {
2025 file_oomem(ms, len);
2029 file_replace(struct magic_set *ms, const char *pat, const char *rep)
2034 - rc = file_regcomp(ms, &rx, pat, REG_EXTENDED);
2038 - while (file_regexec(ms, &rx, ms->o.buf, 1, &rm, 0) == 0) {
2039 - ms->o.buf[rm.rm_so] = '\0';
2040 - if (file_printf(ms, "%s%s", rep,
2041 - rm.rm_eo != 0 ? ms->o.buf + rm.rm_eo : "") == -1)
2063 + res = php_pcre_replace_impl(pce, NULL, ms->o.buf, strlen(ms->o.buf), repl, -1, &rep_cnt);
2076 -check_regex(struct magic_set *ms, const char *pat)
2081 + memcpy(ms->o.buf, ZSTR_VAL(res), ZSTR_LEN(res));
2082 + ms->o.buf[ZSTR_LEN(res)] = '\0';
2089 - file_magwarn(ms,
2092 - file_printable(ms, sbuf, sizeof(sbuf), pat, len));
2100 - file_magwarn(ms,
2102 - c, file_printable(ms, sbuf, sizeof(sbuf), pat, len));
2110 -file_regcomp(struct magic_set *ms file_locale_used, file_regex_t *rx,
2113 - if (check_regex(ms, pat) == -1)
2117 - locale_t old = uselocale(ms->c_lc_ctype);
2132 - if (rc > 0 && (ms->flags & MAGIC_CHECK)) {
2136 - file_magerror(ms, "regex error %d for `%s', (%s)", rc,
2137 - file_printable(ms, buf, sizeof(buf), pat, strlen(pat)),
2145 -file_regexec(struct magic_set *ms file_locale_used, file_regex_t *rx,
2149 - locale_t old = uselocale(ms->c_lc_ctype);
2179 if (ms->event_flags & EVENT_HAD_ERR)
2186 pb->buf = ms->o.buf;
2190 if (ms->event_flags & EVENT_HAD_ERR) {
2199 ms->o.blen = pb->blen;
2200 ms->offset = pb->offset;
2456 return file_apprentice(ms, magicfile, FILE_LOAD);
2464 -magic_load_buffers(struct magic_set *ms, void **bufs, size_t *sizes,
2467 - if (ms == NULL)
2469 - return buffer_apprentice(ms, RCAST(struct magic **, bufs),
2475 magic_compile(struct magic_set *ms, const char *magicfile)
2478 return file_apprentice(ms, magicfile, FILE_LIST);
2482 -close_and_restore(const struct magic_set *ms, const char *name, int fd,
2489 - if ((ms->flags & MAGIC_PRESERVE_ATIME) != 0) {
2519 if (ms == NULL)
2521 - return file_or_fd(ms, NULL, fd);
2522 + return file_or_stream(ms, NULL, NULL);
2528 if (ms == NULL)
2530 - return file_or_fd(ms, inname, STDIN_FILENO);
2531 + return file_or_stream(ms, inname, NULL);
2535 +magic_stream(struct magic_set *ms, php_stream *stream)
2537 + if (ms == NULL)
2539 + return file_or_stream(ms, NULL, stream);
2543 -file_or_fd(struct magic_set *ms, const char *inname, int fd)
2544 +file_or_stream(struct magic_set *ms, const char *inname, php_stream *stream)
2556 if (file_reset(ms, 1) == -1)
2562 - if ((buf = CAST(unsigned char *, malloc(ms->bytes_max + SLOP))) == NULL)
2563 + if ((buf = CAST(unsigned char *, emalloc(ms->bytes_max + SLOP))) == NULL)
2566 switch (file_fsmagic(ms, inname, &sb)) {
2594 - unreadable_info(ms, sb.st_mode, inname) == -1)
2601 + if (unreadable_info(ms, sb.st_mode, inname) == -1)
2620 + if (ms->flags & MAGIC_ERROR) {
2621 + file_error(ms, errno, "cannot stat `%s'", inname);
2629 * try looking at the first ms->bytes_max bytes
2636 - CAST(size_t, ms->bytes_max - nbytes), 1)) > 0) {
2644 - if (unreadable_info(ms, sb.st_mode, inname) == -1)
2656 - ms->bytes_max;
2659 - file_error(ms, errno, "cannot read fd %d", fd);
2661 - file_error(ms, errno, "cannot read `%s'",
2665 + if ((nbytes = php_stream_read(stream, (char *)buf, ms->bytes_max - nbytes)) < 0) {
2666 + file_error(ms, errno, "cannot read `%s'", inname);
2671 - if (file_buffer(ms, fd, okstat ? &sb : NULL, inname, buf, CAST(size_t, nbytes)) == -1)
2672 + if (file_buffer(ms, stream, &sb, inname, buf, CAST(size_t, nbytes)) == -1)
2680 - close_and_restore(ms, inname, fd, &sb);
2687 return rv == 0 ? file_getbuffer(ms) : NULL;
2692 - if (file_buffer(ms, -1, NULL, NULL, buf, nb) == -1) {
2693 + if (file_buffer(ms, NULL, NULL, NULL, buf, nb) == -1) {
2696 return file_getbuffer(ms);
2763 file_magwarn(struct magic_set *ms, const char *f, ...)
2772 - if (ms && ms->file)
2773 - (void) fprintf(stderr, "%s, %lu: ", ms->file,
2774 - CAST(unsigned long, ms->line));
2887 if (!NOTMIME(ms) && root_storage)
2891 if (file_printf(ms, "%s%s",
2900 } else if (ms->flags & MAGIC_MIME_TYPE) {
2901 if (file_printf(ms, "application/CDFV2") == -1)
2906 m = cdf_file_property_info(ms, info, count, root_storage);
2951 for (ml = ms->mlist[0]->next; ml != ms->mlist[0]; ml = ml->next) {
2952 - int ret = match(ms, ml->magic, ml->magic_rxcomp, ml->nmagic, b,
2953 + int ret = match(ms, ml->magic, ml->nmagic, b,
2988 -match(struct magic_set *ms, struct magic *magic, file_regex_t **magic_rxcomp,
2989 +match(struct magic_set *ms, struct magic *magic,
3009 - switch (magiccheck(ms, m, m_rxcomp)) {
3010 + switch (magiccheck(ms, m)) {
3019 ms->line = m->lineno; /* for messages */
3026 - switch (flush ? 1 : magiccheck(ms, m, m_rxcomp)) {
3027 + switch (flush ? 1 : magiccheck(ms, m)) {
3033 check_fmt(struct magic_set *ms, const char *fmt)
3045 - rc = file_regcomp(ms, &rx, pat, REG_EXTENDED|REG_NOSUB);
3047 - rc = file_regexec(ms, &rx, fmt, 0, 0, 0);
3078 - cp = strndup(RCAST(const char *, ms->search.s),
3079 + cp = estrndup(RCAST(const char *, ms->search.s),
3080 ms->search.rm_len);
3082 file_oomem(ms, ms->search.rm_len);
3085 rval = file_printf(ms, F(ms, desc, "%s"), file_printable(ms,
3086 sbuf, sizeof(sbuf), scp, ms->search.rm_len));
3094 *c = ms->c;
3096 - ms->c.li = CAST(struct level_info *, malloc(len));
3097 + ms->c.li = CAST(struct level_info *, emalloc(len));
3098 if (ms->c.li == NULL) {
3099 ms->c = *c;
3103 restore_cont(struct magic_set *ms, struct cont *c)
3105 - free(ms->c.li);
3106 + efree(ms->c.li);
3107 ms->c = *c;
3111 for (mlp = ms->mlist[0]->next; mlp != ms->mlist[0];
3114 - if ((rv = match(ms, mlp->magic, mlp->magic_rxcomp,
3115 + if ((rv = match(ms, mlp->magic,
3120 if ((ms->flags & MAGIC_NODESC) == 0 &&
3121 file_printf(ms, F(ms, m->desc, "%u"), offset) == -1)
3127 if (file_printf(ms, "%s", rbuf) == -1) {
3141 eoffset = ms->eoffset;
3142 - rv = match(ms, ml.magic, ml.magic_rxcomp, ml.nmagic, b,
3143 + rv = match(ms, ml.magic, ml.nmagic, b,
3169 -alloc_regex(struct magic_set *ms, struct magic *m)
3175 - file_error(ms, errno, "can't allocate %" SIZE_T_FORMAT
3180 - rc = file_regcomp(ms, rx, m->value.s, REG_EXTENDED | REG_NEWLINE |
3190 -magiccheck(struct magic_set *ms, struct magic *m, file_regex_t **m_cache)
3191 +magiccheck(struct magic_set *ms, struct magic *m)
3199 - if ((ms->flags & MAGIC_DEBUG) != 0) {
3200 - size_t xlen = ms->search.s_len > 100 ? 100
3201 - : ms->search.s_len;
3204 - file_showstr(stderr, ms->search.s, xlen);
3205 - fprintf(stderr, "%s] for [", ms->search.s_len == xlen
3213 if (m->str_range == 0 || ms->search.s_len < idx)
3214 idx = ms->search.s_len;
3215 - found = CAST(const char *, memmem(ms->search.s, idx,
3217 - if ((ms->flags & MAGIC_DEBUG) != 0) {
3221 + found = CAST(const char *, php_memnstr(ms->search.s,
3222 + m->value.s, slen, ms->search.s + idx));
3230 - if ((ms->flags & MAGIC_DEBUG) != 0) {
3240 - size_t slen = ms->search.s_len;
3246 - if (ms->search.s == NULL)
3251 - rx = *m_cache = alloc_regex(ms, m);
3261 - file_error(ms, errno,
3266 - memcpy(copy, ms->search.s, slen);
3273 - rc = file_regexec(ms, rx, RCAST(const char *, search),
3278 - ms->search.s += CAST(int, pmatch.rm_so);
3279 - ms->search.offset += CAST(size_t, pmatch.rm_so);
3280 - ms->search.rm_len = CAST(size_t,
3305 + haystack = zend_string_init(ms->search.s, ms->search.s_len, 0);
3331 + ms->search.s += Z_LVAL_P(offset); /* this is where the match starts */
3332 + ms->search.offset += Z_LVAL_P(offset); /* this is where the match starts as size_t */
3333 + ms->search.rm_len = Z_STRLEN_P(match) /* This is the length of the matched pattern */;