diff options
author | Felipe Pena <felipe@php.net> | 2008-08-27 00:17:27 +0000 |
---|---|---|
committer | Felipe Pena <felipe@php.net> | 2008-08-27 00:17:27 +0000 |
commit | 1ef7dfce3d4f60de760dd4ba13fe5325ca009592 (patch) | |
tree | c042ce3a85ebc747adfbc51661c0067deb6be1be /ext/fileinfo | |
parent | c1f52e5868781b11b681bf48ea3b2e870980c924 (diff) | |
download | php-git-1ef7dfce3d4f60de760dd4ba13fe5325ca009592.tar.gz |
- MFH: Fixed crash in file_error_core()
Diffstat (limited to 'ext/fileinfo')
-rw-r--r-- | ext/fileinfo/libmagic/funcs.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/ext/fileinfo/libmagic/funcs.c b/ext/fileinfo/libmagic/funcs.c index 22e277b611..b891679510 100644 --- a/ext/fileinfo/libmagic/funcs.c +++ b/ext/fileinfo/libmagic/funcs.c @@ -52,7 +52,6 @@ protected int file_printf(struct magic_set *ms, const char *fmt, ...) { va_list ap; - size_t size; int len; char *buf = NULL, *newstr; @@ -81,17 +80,32 @@ private void file_error_core(struct magic_set *ms, int error, const char *f, va_list va, uint32_t lineno) { + char *buf = NULL; + /* Only the first error is ok */ - if (ms->haderr) + if (ms->haderr) { return; + } + if (lineno != 0) { efree(ms->o.buf); ms->o.buf = NULL; file_printf(ms, "line %u: ", lineno); } - file_printf(ms, f, va); - if (error > 0) - file_printf(ms, " (%s)", strerror(error)); + + vspprintf(&buf, 0, f, va); + va_end(va); + + if (error > 0) { + file_printf(ms, "%s (%s)", (*buf ? buf : ""), strerror(error)); + } else if (*buf) { + file_printf(ms, "%s", buf); + } + + if (buf) { + efree(buf); + } + ms->haderr++; ms->error = error; } |