]> granicus.if.org Git - php/commitdiff
Fixed segfault in case the specified magic file cannot be read.
authorMoriyoshi Koizumi <moriyoshi@php.net>
Fri, 15 Nov 2002 15:13:30 +0000 (15:13 +0000)
committerMoriyoshi Koizumi <moriyoshi@php.net>
Fri, 15 Nov 2002 15:13:30 +0000 (15:13 +0000)
ext/mime_magic/mime_magic.c

index 474182d181b0ef0254a776fb663182fcbad113ad..6e5b308fb9f6ee1bf10d52dee4fce0c2b04948f4 100644 (file)
@@ -304,6 +304,11 @@ PHP_FUNCTION(mime_content_type)
                return;
        }
 
+       if ((int) conf->magic == -1) {
+               php_error(E_ERROR, MODNAME " could not be initialized, magic file %s is not avaliable",  conf->magicfile);
+               RETURN_FALSE;
+       } 
+
        if(!conf->magic) {
                php_error(E_WARNING, MODNAME " not initialized");
                RETURN_FALSE;
@@ -343,10 +348,9 @@ static int apprentice(void)
     magic_server_config_rec *conf = &mime_global;
 
     fname = conf->magicfile; /* todo cwd? */
-    f = fopen(fname, "r");
+    f = fopen(fname, "rt");
     if (f == NULL) {
-               php_error(E_WARNING,
-                                        MODNAME ": can't read magic file %s", fname);
+               (int) conf->magic = -1;
                return -1;
     }