Could you try the attached patch and see if it fixes the problem.

Ilia

On November 14, 2002 03:10 pm, Moriyoshi Koizumi wrote:
> Hi,
>
> I found a bug in mime_magic. If the module fails to read the magic file
> specified by mime_magic.magicfile during the module initialisation, it
> tries to put an error, and then segfaults.
>
> Here's the backtrace.
>
> #0  0x0813402b in sapi_send_headers (tsrm_ls=0x8277f68)
>     at /home/koizumi/src/php.net/HEAD/php4/main/SAPI.c:673
> #1  0x080e5ce2 in php_header ()
>     at /home/koizumi/src/php.net/HEAD/php4/ext/standard/head.c:62
> #2  0x08171433 in sapi_cli_log_message (
>     message=0x82a5c74 "PHP Warning:  mime_magic: can't read magic file
> .ext/mime _magic/tests/magic.test.1 in Unknown on line 0")
>     at /home/koizumi/src/php.net/HEAD/php4/sapi/cli/php_cli.c:174
> #3  0x0812d639 in php_log_err (
>     log_message=0x82a5c74 "PHP Warning:  mime_magic: can't read magic file
> .ext/ mime_magic/tests/magic.test.1 in Unknown on line 0",
> tsrm_ls=0x8277f68) at /home/koizumi/src/php.net/HEAD/php4/main/main.c:360
> #4  0x0812dc9a in php_error_cb (type=2, error_filename=0x8228eab "Unknown",
>     error_lineno=0, format=0x81fcb00 "mime_magic: can't read magic file
> %s", args=0xbfffd7b8) at
> /home/koizumi/src/php.net/HEAD/php4/main/main.c:600 #5  0x081581d9 in
> zend_error (type=2,
>     format=0x81fcb00 "mime_magic: can't read magic file %s")
>     at /home/koizumi/src/php.net/HEAD/php4/Zend/zend.c:711
> #6  0x080b2206 in apprentice ()
>     at /home/koizumi/src/php.net/HEAD/php4/ext/mime_magic/mime_magic.c:348
> #7  0x080b1f4e in zm_startup_mime_magic (type=1, module_number=9,
>     tsrm_ls=0x8277f68)
>     at /home/koizumi/src/php.net/HEAD/php4/ext/mime_magic/mime_magic.c:266
> #8  0x0815a053 in zend_startup_module (module=0x82577a0)
>     at /home/koizumi/src/php.net/HEAD/php4/Zend/zend_API.c:1008
> #9  0x0812ec2b in php_startup_extensions (ptr=0x82621a0, count=15)
>     at /home/koizumi/src/php.net/HEAD/php4/main/main.c:974
> #10 0x08172732 in php_startup_internal_extensions ()
>     at main/internal_functions_cli.c:79
> #11 0x0812f090 in php_module_startup (sf=0x8261f60, additional_modules=0x0,
>     num_additional_modules=0)
>     at /home/koizumi/src/php.net/HEAD/php4/main/main.c:1138
> #12 0x08171955 in main (argc=1, argv=0xbffffa94)
>     at /home/koizumi/src/php.net/HEAD/php4/sapi/cli/php_cli.c:446
> #13 0x40318507 in __libc_start_main (main=0x81717e8 <main>, argc=1,
>     ubp_av=0xbffffa94, init=0x80671f8 <_init>, fini=0x8172770 <_fini>,
>     rtld_fini=0x4000dc14 <_dl_fini>, stack_end=0xbffffa8c)
>     at ../sysdeps/generic/libc-start.c:129
>
>
> IMO php_error() should not be used in PHP_MINIT_FUNCTION. Any fix else?
>
>
> Moriyoshi
Index: mime_magic.c
===================================================================
RCS file: /repository/php4/ext/mime_magic/mime_magic.c,v
retrieving revision 1.13
diff -u -3 -p -r1.13 mime_magic.c
--- mime_magic.c        4 Oct 2002 19:01:34 -0000       1.13
+++ mime_magic.c        15 Nov 2002 03:24:35 -0000
@@ -304,6 +304,11 @@ PHP_FUNCTION(mime_content_type)
                return;
        }
 
+       if ((int) conf->magic == -1) {
+                zend_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,13 +348,12 @@ static int apprentice(void)
     magic_server_config_rec *conf = &mime_global;
 
     fname = conf->magicfile; // todo cwd?
-    f = fopen(fname, "r");
+    f = fopen(fname, "rb");
     if (f == NULL) {
-               php_error(E_WARNING,
-                                        MODNAME ": can't read magic file %s", fname);
-               return -1;
+       (int) conf->magic = -1;
+       return -1;
     }
-
+    
     /* set up the magic list (empty) */
     conf->magic = conf->last = NULL;
 

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to