Discussion:
[freetds] help debugging segfault
Mark A. Hershberger
2013-03-04 01:55:18 UTC
Permalink
I'm working on enabling a connection to Azure's SQL server from PHP (see
https://bugs.php.net/bug.php?id=64338).

The connection now works -- at least, I can connect to a database other
than the master one -- but since errors from the server are only
available from the debug log that FreeTDS has, I need to enable the
debug log.

The problem: I get a segfault after turning on debugging.

The end of the log is included at [1].

I've also included a backtrace from gdb at [2].

Is this a bug in FreeTDS? Or is the way I set up the connection from
PHP wrong?

[1] Debug log end
20:05:03.365572 867 (token.c:2355):tds_process_end() state set to TDS_IDLE
20:05:03.365583 867 (util.c:156):Changed query state from READING to IDLE
20:05:03.365595 867 (token.c:2370): rows_affected = 0
20:05:03.365606 867 (util.c:104):logic error: cannot change query state
from IDLE to PENDING
20:05:03.365618 867 (token.c:540):tds_process_tokens(0x1014090,
0x7fffffff9b08, 0x7fffffff9b0c, 0x100)
20:05:03.365630 867 (token.c:543):tds_process_tokens() state is COMPLETED
20:05:03.365641 867 (login.c:496):successful login
20:05:03.365656 867 (dblib.c:239):dblib_add_connection(0x7ffff0464640,
0x1014090)
20:05:03.365682 867 (dblib.c:4317):dbsetopt(0x1013520, 17, 2147483647, -1)
20:05:03.365697 867 (dblib.c:4386):Got DBTEXTSIZE, with param
'2147483647' (max is 2147483647)

(I added the "successful login" and the "Got DBTEXTSIZE" messages.)

[2] Backtrace from gdb

(gdb) bt
#0 0x00007ffff4da3304 in vfprintf () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x00007ffff023d769 in ?? () from /usr/lib/x86_64-linux-gnu/libsybdb.so.5
#2 0x00007ffff020f774 in dbsetopt () from
/usr/lib/x86_64-linux-gnu/libsybdb.so.5
#3 0x00007fffeeae4629 in pdo_dblib_handle_factory (dbh=0x7ffff7fc4b70,
driver_options=0x7fffffe9)
at
/home/mah/work/DEB-BUILD/build-dir/php5-5.4.4/ext/pdo_dblib/dblib_driver.c:323
#4 0x00007ffff3e9fa41 in zim_PDO_dbh_constructor (ht=1,
return_value=0x7fffffe9, return_value_ptr=0x30,
this_ptr=0x7ffff7fc4b40, return_value_used=1) at
/home/mah/work/DEB-BUILD/build-dir/php5-5.4.4/ext/pdo/pdo_dbh.c:380
#5 0x00007ffff40c2edc in xdebug_execute_internal
(current_execute_data=0x7ffff7f8f060, return_value_used=0)
at /tmp/buildd/xdebug-2.2.1/build-php5/xdebug.c:1483
#6 0x00000000007468be in zend_do_fcall_common_helper_SPEC
(execute_data=0x7ffff7f8f060)
at
/home/mah/work/DEB-BUILD/build-dir/php5-5.4.4/Zend/zend_vm_execute.h:644
#7 0x00000000007002c7 in execute (op_array=0x7ffff7fc4070)
at
/home/mah/work/DEB-BUILD/build-dir/php5-5.4.4/Zend/zend_vm_execute.h:410
#8 0x00007ffff40c2a81 in xdebug_execute (op_array=0x7ffff7fc4070) at
/tmp/buildd/xdebug-2.2.1/build-php5/xdebug.c:1391
#9 0x00000000006a010e in zend_execute_scripts (type=8,
retval=0x7ffff7fc3800, file_count=3)
at /home/mah/work/DEB-BUILD/build-dir/php5-5.4.4/Zend/zend.c:1279
#10 0x000000000063f6e3 in php_execute_script (primary_file=0x7ffff4d9edbc)
at /home/mah/work/DEB-BUILD/build-dir/php5-5.4.4/main/main.c:2473
#11 0x0000000000749033 in do_cli (argc=0, argv=0x7fffffffe18b)
at /home/mah/work/DEB-BUILD/build-dir/php5-5.4.4/sapi/cli/php_cli.c:988
#12 0x00000000004310ca in main (argc=32767, argv=0xdb9210)
at /home/mah/work/DEB-BUILD/build-dir/php5-5.4.4/sapi/cli/php_cli.c:1361
--
http://hexmode.com/

Many that live deserve death. And some that die deserve life. Can you
give it to them? Then do not be too eager to deal out death in
judgment. For even the very wise cannot see all ends.
-- J.R.R. Tolkien, The Fellowship of the Ring
Frediano Ziglio
2013-03-04 08:10:33 UTC
Permalink
Error came from this line
(http://git.php.net/?p=php-src.git;a=blob;f=ext/pdo_dblib/dblib_driver.c;h=77832f952047d8e3614bb46a49f7b7ca56e98d86;hb=e961c76a0bf81dbf7322fbd87fafc0642b6bef62)

/* allow double quoted indentifiers */
DBSETOPT(H->link, DBQUOTEDIDENT, 1);

PHP pass a number as a pointer to string!
"Note The param variable must always be a character string enclosed
in quotation marks, even in the case of a numeric value, as in the
preceding DBBUFFER example."

Frediano
Post by Mark A. Hershberger
I'm working on enabling a connection to Azure's SQL server from PHP (see
https://bugs.php.net/bug.php?id=64338).
The connection now works -- at least, I can connect to a database other
than the master one -- but since errors from the server are only
available from the debug log that FreeTDS has, I need to enable the
debug log.
The problem: I get a segfault after turning on debugging.
The end of the log is included at [1].
I've also included a backtrace from gdb at [2].
Is this a bug in FreeTDS? Or is the way I set up the connection from
PHP wrong?
[1] Debug log end
20:05:03.365572 867 (token.c:2355):tds_process_end() state set to TDS_IDLE
20:05:03.365583 867 (util.c:156):Changed query state from READING to IDLE
20:05:03.365595 867 (token.c:2370): rows_affected = 0
20:05:03.365606 867 (util.c:104):logic error: cannot change query state
from IDLE to PENDING
20:05:03.365618 867 (token.c:540):tds_process_tokens(0x1014090,
0x7fffffff9b08, 0x7fffffff9b0c, 0x100)
20:05:03.365630 867 (token.c:543):tds_process_tokens() state is COMPLETED
20:05:03.365641 867 (login.c:496):successful login
20:05:03.365656 867 (dblib.c:239):dblib_add_connection(0x7ffff0464640,
0x1014090)
20:05:03.365682 867 (dblib.c:4317):dbsetopt(0x1013520, 17, 2147483647, -1)
20:05:03.365697 867 (dblib.c:4386):Got DBTEXTSIZE, with param
'2147483647' (max is 2147483647)
(I added the "successful login" and the "Got DBTEXTSIZE" messages.)
[2] Backtrace from gdb
(gdb) bt
#0 0x00007ffff4da3304 in vfprintf () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x00007ffff023d769 in ?? () from /usr/lib/x86_64-linux-gnu/libsybdb.so.5
#2 0x00007ffff020f774 in dbsetopt () from
/usr/lib/x86_64-linux-gnu/libsybdb.so.5
#3 0x00007fffeeae4629 in pdo_dblib_handle_factory (dbh=0x7ffff7fc4b70,
driver_options=0x7fffffe9)
at
/home/mah/work/DEB-BUILD/build-dir/php5-5.4.4/ext/pdo_dblib/dblib_driver.c:323
#4 0x00007ffff3e9fa41 in zim_PDO_dbh_constructor (ht=1,
return_value=0x7fffffe9, return_value_ptr=0x30,
this_ptr=0x7ffff7fc4b40, return_value_used=1) at
/home/mah/work/DEB-BUILD/build-dir/php5-5.4.4/ext/pdo/pdo_dbh.c:380
#5 0x00007ffff40c2edc in xdebug_execute_internal
(current_execute_data=0x7ffff7f8f060, return_value_used=0)
at /tmp/buildd/xdebug-2.2.1/build-php5/xdebug.c:1483
#6 0x00000000007468be in zend_do_fcall_common_helper_SPEC
(execute_data=0x7ffff7f8f060)
at
/home/mah/work/DEB-BUILD/build-dir/php5-5.4.4/Zend/zend_vm_execute.h:644
#7 0x00000000007002c7 in execute (op_array=0x7ffff7fc4070)
at
/home/mah/work/DEB-BUILD/build-dir/php5-5.4.4/Zend/zend_vm_execute.h:410
#8 0x00007ffff40c2a81 in xdebug_execute (op_array=0x7ffff7fc4070) at
/tmp/buildd/xdebug-2.2.1/build-php5/xdebug.c:1391
#9 0x00000000006a010e in zend_execute_scripts (type=8,
retval=0x7ffff7fc3800, file_count=3)
at /home/mah/work/DEB-BUILD/build-dir/php5-5.4.4/Zend/zend.c:1279
#10 0x000000000063f6e3 in php_execute_script (primary_file=0x7ffff4d9edbc)
at /home/mah/work/DEB-BUILD/build-dir/php5-5.4.4/main/main.c:2473
#11 0x0000000000749033 in do_cli (argc=0, argv=0x7fffffffe18b)
at /home/mah/work/DEB-BUILD/build-dir/php5-5.4.4/sapi/cli/php_cli.c:988
#12 0x00000000004310ca in main (argc=32767, argv=0xdb9210)
at /home/mah/work/DEB-BUILD/build-dir/php5-5.4.4/sapi/cli/php_cli.c:1361
--
http://hexmode.com/
Many that live deserve death. And some that die deserve life. Can you
give it to them? Then do not be too eager to deal out death in
judgment. For even the very wise cannot see all ends.
-- J.R.R. Tolkien, The Fellowship of the Ring
_______________________________________________
FreeTDS mailing list
FreeTDS at lists.ibiblio.org
http://lists.ibiblio.org/mailman/listinfo/freetds
Chris Bandy
2013-03-04 09:10:03 UTC
Permalink
Hah. Since summer 2010. And the commit message for that line is "Actually
fix quoted identifiers this time".

-- Chris
Post by Frediano Ziglio
Error came from this line
(
http://git.php.net/?p=php-src.git;a=blob;f=ext/pdo_dblib/dblib_driver.c;h=77832f952047d8e3614bb46a49f7b7ca56e98d86;hb=e961c76a0bf81dbf7322fbd87fafc0642b6bef62
)
/* allow double quoted indentifiers */
DBSETOPT(H->link, DBQUOTEDIDENT, 1);
PHP pass a number as a pointer to string!
"Note The param variable must always be a character string enclosed
in quotation marks, even in the case of a numeric value, as in the
preceding DBBUFFER example."
Frediano
Post by Mark A. Hershberger
I'm working on enabling a connection to Azure's SQL server from PHP (see
https://bugs.php.net/bug.php?id=64338).
The connection now works -- at least, I can connect to a database other
than the master one -- but since errors from the server are only
available from the debug log that FreeTDS has, I need to enable the
debug log.
The problem: I get a segfault after turning on debugging.
The end of the log is included at [1].
I've also included a backtrace from gdb at [2].
Is this a bug in FreeTDS? Or is the way I set up the connection from
PHP wrong?
[1] Debug log end
20:05:03.365572 867 (token.c:2355):tds_process_end() state set to
TDS_IDLE
Post by Mark A. Hershberger
20:05:03.365583 867 (util.c:156):Changed query state from READING to IDLE
20:05:03.365595 867 (token.c:2370): rows_affected = 0
20:05:03.365606 867 (util.c:104):logic error: cannot change query state
from IDLE to PENDING
20:05:03.365618 867 (token.c:540):tds_process_tokens(0x1014090,
0x7fffffff9b08, 0x7fffffff9b0c, 0x100)
20:05:03.365630 867 (token.c:543):tds_process_tokens() state is COMPLETED
20:05:03.365641 867 (login.c:496):successful login
20:05:03.365656 867 (dblib.c:239):dblib_add_connection(0x7ffff0464640,
0x1014090)
20:05:03.365682 867 (dblib.c:4317):dbsetopt(0x1013520, 17, 2147483647,
-1)
Post by Mark A. Hershberger
20:05:03.365697 867 (dblib.c:4386):Got DBTEXTSIZE, with param
'2147483647' (max is 2147483647)
(I added the "successful login" and the "Got DBTEXTSIZE" messages.)
[2] Backtrace from gdb
(gdb) bt
#0 0x00007ffff4da3304 in vfprintf () from
/lib/x86_64-linux-gnu/libc.so.6
Post by Mark A. Hershberger
#1 0x00007ffff023d769 in ?? () from
/usr/lib/x86_64-linux-gnu/libsybdb.so.5
Post by Mark A. Hershberger
#2 0x00007ffff020f774 in dbsetopt () from
/usr/lib/x86_64-linux-gnu/libsybdb.so.5
#3 0x00007fffeeae4629 in pdo_dblib_handle_factory (dbh=0x7ffff7fc4b70,
driver_options=0x7fffffe9)
at
/home/mah/work/DEB-BUILD/build-dir/php5-5.4.4/ext/pdo_dblib/dblib_driver.c:323
Post by Mark A. Hershberger
#4 0x00007ffff3e9fa41 in zim_PDO_dbh_constructor (ht=1,
return_value=0x7fffffe9, return_value_ptr=0x30,
this_ptr=0x7ffff7fc4b40, return_value_used=1) at
/home/mah/work/DEB-BUILD/build-dir/php5-5.4.4/ext/pdo/pdo_dbh.c:380
#5 0x00007ffff40c2edc in xdebug_execute_internal
(current_execute_data=0x7ffff7f8f060, return_value_used=0)
at /tmp/buildd/xdebug-2.2.1/build-php5/xdebug.c:1483
#6 0x00000000007468be in zend_do_fcall_common_helper_SPEC
(execute_data=0x7ffff7f8f060)
at
/home/mah/work/DEB-BUILD/build-dir/php5-5.4.4/Zend/zend_vm_execute.h:644
#7 0x00000000007002c7 in execute (op_array=0x7ffff7fc4070)
at
/home/mah/work/DEB-BUILD/build-dir/php5-5.4.4/Zend/zend_vm_execute.h:410
#8 0x00007ffff40c2a81 in xdebug_execute (op_array=0x7ffff7fc4070) at
/tmp/buildd/xdebug-2.2.1/build-php5/xdebug.c:1391
#9 0x00000000006a010e in zend_execute_scripts (type=8,
retval=0x7ffff7fc3800, file_count=3)
at /home/mah/work/DEB-BUILD/build-dir/php5-5.4.4/Zend/zend.c:1279
#10 0x000000000063f6e3 in php_execute_script
(primary_file=0x7ffff4d9edbc)
Post by Mark A. Hershberger
at /home/mah/work/DEB-BUILD/build-dir/php5-5.4.4/main/main.c:2473
#11 0x0000000000749033 in do_cli (argc=0, argv=0x7fffffffe18b)
at
/home/mah/work/DEB-BUILD/build-dir/php5-5.4.4/sapi/cli/php_cli.c:988
Post by Mark A. Hershberger
#12 0x00000000004310ca in main (argc=32767, argv=0xdb9210)
at
/home/mah/work/DEB-BUILD/build-dir/php5-5.4.4/sapi/cli/php_cli.c:1361
Post by Mark A. Hershberger
--
http://hexmode.com/
Many that live deserve death. And some that die deserve life. Can you
give it to them? Then do not be too eager to deal out death in
judgment. For even the very wise cannot see all ends.
-- J.R.R. Tolkien, The Fellowship of the Ring
_______________________________________________
FreeTDS mailing list
FreeTDS at lists.ibiblio.org
http://lists.ibiblio.org/mailman/listinfo/freetds
_______________________________________________
FreeTDS mailing list
FreeTDS at lists.ibiblio.org
http://lists.ibiblio.org/mailman/listinfo/freetds
Mark A. Hershberger
2013-03-04 15:53:24 UTC
Permalink
Post by Frediano Ziglio
/* allow double quoted indentifiers */
DBSETOPT(H->link, DBQUOTEDIDENT, 1);
PHP pass a number as a pointer to string!
Thank you! This fixed it.

Now, the error messages returned from by PHP are useless. I'll look for
a way to fix this, but right now I get the following:

Error: [HY000] General SQL Server error: Check messages from the SQL
Server [102] (severity 15) [sql here here with a MySQL create table]

The relevant line in the debug log is:

(dbutil.c:86):msgno 102: "Incorrect syntax near 'AUTO_INCREMENT'."

I'll try to get this fixed, but if you have any suggestions, I'm open!

Thanks again!
--
http://hexmode.com/

Many that live deserve death. And some that die deserve life. Can you
give it to them? Then do not be too eager to deal out death in
judgment. For even the very wise cannot see all ends.
-- J.R.R. Tolkien, The Fellowship of the Ring
Frediano Ziglio
2013-03-04 19:18:32 UTC
Permalink
Post by Mark A. Hershberger
Post by Frediano Ziglio
/* allow double quoted indentifiers */
DBSETOPT(H->link, DBQUOTEDIDENT, 1);
PHP pass a number as a pointer to string!
Thank you! This fixed it.
Now, the error messages returned from by PHP are useless. I'll look for
Error: [HY000] General SQL Server error: Check messages from the SQL
Server [102] (severity 15) [sql here here with a MySQL create table]
(dbutil.c:86):msgno 102: "Incorrect syntax near 'AUTO_INCREMENT'."
I'll try to get this fixed, but if you have any suggestions, I'm open!
Thanks again!
Hi,
you are trying to speak mysql to mssql! The syntax is different,
probably you have something like

create table table_name
(
id int identity primary key,
...
)

Frediano
Mark A. Hershberger
2013-03-04 19:49:08 UTC
Permalink
Post by Frediano Ziglio
you are trying to speak mysql to mssql! The syntax is different,
I do realize that. My plea is for better feedback and error reporting.

After looking at this a bit today, I see the problem is definitely on
the PHP side, not the dblib side.

Thank you, in any case.

Mark.
--
http://hexmode.com/

Many that live deserve death. And some that die deserve life. Can you
give it to them? Then do not be too eager to deal out death in
judgment. For even the very wise cannot see all ends.
-- J.R.R. Tolkien, The Fellowship of the Ring
Loading...