]> granicus.if.org Git - php/commitdiff
MFH Fix bug #46331 - The internal magic db is const memory and segfaults when you...
authorScott MacVicar <scottmac@php.net>
Mon, 20 Oct 2008 23:36:14 +0000 (23:36 +0000)
committerScott MacVicar <scottmac@php.net>
Mon, 20 Oct 2008 23:36:14 +0000 (23:36 +0000)
on big endian machines. This fixes it by copying the memory for those processors, but this isn't ideal as
it wastes memory. Perhaps using a static cache would be better.

ext/fileinfo/libmagic/apprentice.c

index d4e0e889d5601ed711a2048b5d2c0322ad17b623..5e7b9cffdd7b073b2512bb231c4fd28932a431c1 100644 (file)
@@ -1921,6 +1921,16 @@ internal_loaded:
                goto error1;
        }
 
+       /* php_magic_database is a const, performing writes will segfault. This is for big-endian
+       machines only, PPC and Sparc specifically. Consider static variable or MINIT in
+       future. */
+       if (needsbyteswap && fn == NULL) {
+               mm = emalloc(sizeof(php_magic_database));
+               mm = memcpy(mm, php_magic_database, sizeof(php_magic_database));
+               *magicp = mm;
+               ret = 1;
+       }
+
        if (fn == NULL) {
                *nmagicp = (sizeof(php_magic_database) / sizeof(struct magic));
        } else {