Skip to content

Instantly share code, notes, and snippets.

@neerolyte
Last active December 25, 2015 01:59
Show Gist options
  • Save neerolyte/6899314 to your computer and use it in GitHub Desktop.
Save neerolyte/6899314 to your computer and use it in GitHub Desktop.
Segfaulting php when using pcntl functions and postgres
<?php
$dbh = new PDO("pgsql:dbname=test;user=postgres");
if (pcntl_fork()) {
// give child a moment to shutdown
usleep(200000);
// do anything with the db... segfault!
$dbh->query("select version();");
}
@neerolyte
Copy link
Author

Running it produces a segfault:

    $ php pgsql_pdo_segfault.php 
    Segmentation fault (core dumped)

The core:

    $ gdb core.15868 
    [...]
    Core was generated by `php pgsql_pdo_segfault.php'.
    Program terminated with signal 11, Segmentation fault.
    #0  0x00007ff677627859 in pgsql_stmt_execute (stmt=0x1c3cc58) at /usr/src/debug/php-5.3.3/ext/pdo_pgsql/pgsql_statement.c:187
    187                                             if (!strcmp(sqlstate, "42P05")) {
    (gdb) bt
    #0  0x00007ff677627859 in pgsql_stmt_execute (stmt=0x1c3cc58) at /usr/src/debug/php-5.3.3/ext/pdo_pgsql/pgsql_statement.c:187
    #1  0x00007ff677a3923a in zim_PDO_query (ht=1, return_value=0x1c3ca68, return_value_ptr=0x0, this_ptr=0x1c3ae38, 
        return_value_used=1) at /usr/src/debug/php-5.3.3/ext/pdo/pdo_dbh.c:1125
    #2  0x00000000005f5738 in zend_do_fcall_common_helper_SPEC (execute_data=<value optimized out>)
        at /usr/src/debug/php-5.3.3/Zend/zend_vm_execute.h:316
    #3  0x00000000005cca70 in execute (op_array=0x1c3b5b0) at /usr/src/debug/php-5.3.3/Zend/zend_vm_execute.h:107
    #4  0x00000000005a71ad in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /usr/src/debug/php-5.3.3/Zend/zend.c:1194
    #5  0x0000000000555288 in php_execute_script (primary_file=0x7fff837d82b0) at /usr/src/debug/php-5.3.3/main/main.c:2261
    #6  0x0000000000630ee5 in main (argc=2, argv=0x7fff837d84b8) at /usr/src/debug/php-5.3.3/sapi/cli/php_cli.c:1192
    (gdb) print sqlstate
    $1 = 0x0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment