Bug #75671 [Opn->Csd]: pg_version() crashes when called on a connection to cockroach

From: Date: Fri, 15 Dec 2017 14:35:46 +0000
Subject: Bug #75671 [Opn->Csd]: pg_version() crashes when called on a connection to cockroach
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-213117@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75671&edit=1 ID: 75671 Updated by: ab@php.net Reported by: magicaltux at gmail dot com Summary: pg_version() crashes when called on a connection to cockroach -Status: Open +Status: Closed Type: Bug Package: PostgreSQL related Operating System: Linux Ubuntu 16 LTS PHP Version: 7.2.0 Block user comment: N Private report: N New Comment: Automatic comment on behalf of ab Revision: http://git.php.net/?p=php-src.git;a=commit;h=acf1472ffde08a514fa44ef4b5baa0c67ae1b3f2 Log: Fixed bug #75671 pg_version() crashes when called on a connection to cockroach Previous Comments: ------------------------------------------------------------------------ [2017-12-12 10:00:56] magicaltux at gmail dot com In ext/pgsql/pgsql.c php_pgsql_get_link_info() I have prefixed each add_assoc_string() with a if(tmp) to confirm what data is actually available (calling add_assoc_null() if tmp is NULL). Result was: array(13) { ["client"]=> string(6) "9.5.10" ["protocol"]=> int(3) ["server"]=> string(5) "9.5.0" ["server_encoding"]=> NULL ["client_encoding"]=> string(4) "UTF8" ["is_superuser"]=> NULL ["session_authorization"]=> NULL ["DateStyle"]=> string(3) "ISO" ["IntervalStyle"]=> NULL ["TimeZone"]=> NULL ["integer_datetimes"]=> string(2) "on" ["standard_conforming_strings"]=> string(2) "on" ["application_name"]=> NULL } ------------------------------------------------------------------------ [2017-12-12 09:53:00] magicaltux at gmail dot com Description: ------------ Cockroach server offers a pgsql compatible wire protocol, and supports a large subset of pgsql: https://www.cockroachlabs.com/docs/stable/sql-feature-support.html Calling pg_version() on a cockroach pgsql connection will however result in a segfault. Even if the server doesn't support part of the protocol, php shouldn't segfault because of that. Test script: --------------- $pg = pg_connect("..."); var_dump(pg_version($pg)); Expected result: ---------------- (pg_version() output) Actual result: -------------- Program received signal SIGSEGV, Segmentation fault. strlen () at ../sysdeps/x86_64/strlen.S:106 106 ../sysdeps/x86_64/strlen.S: No such file or directory. (gdb) bt #0 strlen () at ../sysdeps/x86_64/strlen.S:106 #1 0x00000000008f69c2 in add_assoc_string_ex (arg=arg@entry=0x7fffed21d0a0, key=key@entry=0x107dbef "server_encoding", key_len=key_len@entry=15, str=0x0) at /usr/src/php-web-7.2.0/Zend/zend_API.c:1414 #2 0x00000000006fa2a8 in php_pgsql_get_link_info (return_value=0x7fffed21d0a0, entry_type=<optimized out>, execute_data=<optimized out>) at /usr/src/php-web-7.2.0/ext/pgsql/pgsql.c:1649 #3 0x000000000099f426 in ZEND_DO_ICALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/php-web-7.2.0/Zend/zend_vm_execute.h:617 #4 execute_ex (ex=0x0) at /usr/src/php-web-7.2.0/Zend/zend_vm_execute.h:59737 #5 0x00000000009a4f1e in zend_execute (op_array=0x7fffed27c2a0, op_array@entry=0x7fffdfedb320, return_value=0x0, return_value@entry=0x7fffed21d030) at /usr/src/php-web-7.2.0/Zend/zend_vm_execute.h:63763 #6 0x00000000008f3a13 in zend_execute_scripts (type=type@entry=8, retval=0x7fffed21d030, retval@entry=0x0, file_count=file_count@entry=3) at /usr/src/php-web-7.2.0/Zend/zend.c:1496 #7 0x000000000088f040 in php_execute_script (primary_file=primary_file@entry=0x7fffffffd240) at /usr/src/php-web-7.2.0/main/main.c:2592 #8 0x00000000009a72e9 in do_cli (argc=2, argv=0x14c9060) at /usr/src/php-web-7.2.0/sapi/cli/php_cli.c:1011 #9 0x000000000044ea5c in main (argc=2, argv=0x14c9060) at /usr/src/php-web-7.2.0/sapi/cli/php_cli.c:1404 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75671&edit=1

« previous php.bugs (#213117) next »