]> granicus.if.org Git - php/commitdiff
- Fixed crash in file_error_core()
authorFelipe Pena <felipe@php.net>
Wed, 27 Aug 2008 00:16:11 +0000 (00:16 +0000)
committerFelipe Pena <felipe@php.net>
Wed, 27 Aug 2008 00:16:11 +0000 (00:16 +0000)
ext/fileinfo/libmagic/funcs.c

index 22e277b6118802e85fc616f267b94cbc3e909d29..b891679510ac66cc74fe6a5454c05e3ff696f9cc 100644 (file)
@@ -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;
 }