|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-12-10 19:42 UTC] dfs at roaringpenguin dot com
This is difficult (impossible) to reproduce with a short script. Please download and unpack http://www.roaringpenguin.com/segfault.tar.bz2 You need to have PostgreSQL and create a specific database with specific data in it. Here's the README file from the tarball: SUMMARY: PHP segfaults for PHP versions > 4.1.2 ----------------------------------------------- THE SOURCE FILES IN THIS ARCHIVE ARE PROPRIETARY COMMERCIAL SOFTWARE. PLEASE USE THEM ONLY TO DEBUG PHP PROBLEMS. System: Red Hat Linux 8.0 PostgreSQL: 7.2.2, as supplied with Red Hat Linux 8.0 Apache: 1.3.27, configured as follows: ./configure --with-layout=Apache --enable-shared=max \ --enable-rule=SHARED_CORE PHP: Tried 4.2.2, 4.2.3 and 4.3.0RC2, all configured as follows: ./configure --with-pgsql=shared \ --with-gnu-ld \ --with-apxs=/usr/local/apache/bin/apxs HOW TO REPRODUCE: ----------------- 1) Install Apache 1.3.27 and PHP 4.2.2, 4.2.3 or 4.3.0RC2 from source. Configure PostgreSQL 7.2.2 to trust local connections. That is, in /var/lib/pgsql/data/pg_hba.conf, make the local line read thus: local all trust 2) Create and populate the database: createdb -U postgres spam psql -U postgres -d spam < spam-database-dump 3) Copy the PHP files to your document root somewhere convenient. 4) Browse http://your_server/these_php_files/index.php 5) Log in as "admin", password "foo" 6) Click on "Pending Messages" - Apache will segfault. However: Using PHP 4.1.2, configured as above, it works fine. Extensive investigation shows that it's segfaulting inside libpq, inside PQexec, but the function which segfaults is "malloc" which leads me to believe there's memory corruption going on. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 18:00:01 2025 UTC |
Backtrace for Apache 1.3.27 and PHP 4.3.0RC2: Program received signal SIGSEGV, Segmentation fault. 0x42073d65 in _int_malloc () from /lib/i686/libc.so.6 (gdb) where #0 0x42073d65 in _int_malloc () from /lib/i686/libc.so.6 #1 0x42073155 in malloc () from /lib/i686/libc.so.6 #2 0x402bda44 in pqResultAlloc () from /usr/lib/libpq.so.2 #3 0x402be3d5 in getRowDescriptions () from /usr/lib/libpq.so.2 #4 0x402be2f1 in parseInput () from /usr/lib/libpq.so.2 #5 0x402be970 in PQgetResult () from /usr/lib/libpq.so.2 #6 0x402bea78 in PQexec () from /usr/lib/libpq.so.2 #7 0x40251626 in zif_pg_query (ht=135421720, return_value=0x812593c, this_ptr=0x0, return_value_used=1) at /home/dfs/canit-3rdparty-builds/php-4.3.0RC2/ext/pgsql/pgsql.c:931 #8 0x40201692 in execute (op_array=0x80f1e54) at /home/dfs/canit-3rdparty-builds/php-4.3.0RC2/Zend/zend_execute.c:1596 #9 0x40201433 in execute (op_array=0x80f3a84) at /home/dfs/canit-3rdparty-builds/php-4.3.0RC2/Zend/zend_execute.c:1640 #10 0x40201433 in execute (op_array=0x80b0d40) at /home/dfs/canit-3rdparty-builds/php-4.3.0RC2/Zend/zend_execute.c:1640 #11 0x40201433 in execute (op_array=0x80a36a0) at /home/dfs/canit-3rdparty-builds/php-4.3.0RC2/Zend/zend_execute.c:1640 #12 0x40201433 in execute (op_array=0x80a8a24) at /home/dfs/canit-3rdparty-builds/php-4.3.0RC2/Zend/zend_execute.c:1640 #13 0x401f4fdd in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /home/dfs/canit-3rdparty-builds/php-4.3.0RC2/Zend/zend.c:864 #14 0x401d09d4 in php_execute_script (primary_file=0xbffff530) ---Type <return> to continue, or q <return> to quit--- at /home/dfs/canit-3rdparty-builds/php-4.3.0RC2/main/main.c:1549 #15 0x4020525e in apache_php_module_main (r=0x8099974, display_source_mode=0) at /home/dfs/canit-3rdparty-builds/php-4.3.0RC2/sapi/apache/sapi_apache.c:55 #16 0x40205c25 in send_php (r=0x8099974, display_source_mode=0, filename=0x0) at /home/dfs/canit-3rdparty-builds/php-4.3.0RC2/sapi/apache/mod_php4.c:556 #17 0x40205dba in send_parsed_php (r=0x8099974) at /home/dfs/canit-3rdparty-builds/php-4.3.0RC2/sapi/apache/mod_php4.c:571 #18 0x40022174 in ap_invoke_handler (r=0x8099974) at http_config.c:518 #19 0x40038477 in hypot () at http_request.c:1308 #20 0x400384e9 in ap_process_request (r=0x8099974) at http_request.c:1324 #21 0x4002ee39 in child_main (child_num_arg=0) at http_main.c:4603 #22 0x4002eff8 in make_child (s=0x804b7bc, slot=0, now=1039610873) at http_main.c:4718 #23 0x4002f182 in startup_children (number_to_start=5) at http_main.c:4800 #24 0x4002f838 in standalone_main (argc=2, argv=0xbffff9b4) at http_main.c:5108 #25 0x40030100 in ap_main (argc=2, argv=0xbffff9b4) at http_main.c:5456 #26 0x080485b3 in ?? () #27 0x420158d4 in __libc_start_main () from /lib/i686/libc.so.6Are you running on Red Hat 8.0? I consistently get a crash. It's also obvious that the buffer allocated is 135 bytes, and the length of the wrapped string is 138. So if you're not getting a crash, it's just luck. Try this script instead: <?php $x = "ADV:CLAIM YOUR FORTUNE NOW !!MAKE"; $x .= " xxxxxxxxxxHUNDREDS OF THOUSANDSxxxxxxxxxxxx"; $b = "CANITBREAKFOO"; for ($i=0; $i<1000; $i++) { $y = wordwrap($x, 20, $b, 1); } ?> That should exercise malloc() a lot more.Ah, the bug might not show up on Red Hat 7.1, probably because of glibc differences. Anyway, here's my system: $ gcc -v Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2/specs Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --host=i386-redhat-linux --with-system-zlib --enable-__cxa_atexit Thread model: posix gcc version 3.2 20020903 (Red Hat Linux 8.0 3.2-7) $ ldd /usr/local/bin/php libcrypt.so.1 => /lib/libcrypt.so.1 (0x4002f000) libresolv.so.2 => /lib/libresolv.so.2 (0x4005d000) libm.so.6 => /lib/i686/libm.so.6 (0x4006f000) libdl.so.2 => /lib/libdl.so.2 (0x40091000) libnsl.so.1 => /lib/libnsl.so.1 (0x40094000) libc.so.6 => /lib/i686/libc.so.6 (0x42000000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000) $ rpm -q glibc glibc-2.2.93-5 Regards, David.A more dramatic example: The following script, under PHP 4.1.2, prints: Length of original string: 130 Length of break string: 11264 Length of wrapped string: 214127 Size allocated by 4.3.0RC2: 173596 BUFFER OVERFLOW by 40531 bytes! With 4.3.0RC2, it segfaults. -- David. <?php $part = "1234567890 X "; $string = ""; for ($i=0; $i<10; $i++) { $string .= $part; } $break = "a-very-long-break-string-to-clobber-the-heap"; for ($i=0; $i<8; $i++) { $break .= $break; } $linelength = 10; $wrapped = wordwrap($string, $linelength, $break, 1); $textlen = strlen($string); print("Length of original string: $textlen\n"); $breakcharlen = strlen($break); print("Length of break string: $breakcharlen\n"); $newtextlen = strlen($wrapped); print("Length of wrapped string: $newtextlen\n"); $buffer = $textlen + intval(($textlen/$linelength + 1) * $breakcharlen * 1.1) + 1; print("Size allocated by 4.3.0RC2: $buffer\n"); $overflow = $newtextlen - $buffer; if ($overflow > 0) { print ("BUFFER OVERFLOW by $overflow bytes!\n"); } ?>