mariano/node-db — Issue #7: mysql_real_escape_string segfault 11
Author: jimrubenstein
Created: 2012-02-02 15:17:47+00:00
State: open

It seems that the c++ mysql library segfaults when you call `mysql_real_escape_string` and a connection to a mysql server isn't available.

This normally wouldn't be an issue, but when running test suites, I'd like to be able to use most of the db-mysql library without having to stub every method to prevent the whole callstack from being executed. Maybe this is just laziness on my part, but still - a segfault when a connection isn't available doesn't seem good.

The gdb trace shows this as follows:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000381
0x0000000126ca1ff4 in mysql_real_escape_string ()

#0 0x0000000126ca4ff4 in mysql_real_escape_string ()
#1 0x0000000126c62fe5 in node_db_mysql::Connection::escape (this=0x100d009e0, string=@0x7fff5fbfe1e8) at connection.cc:133
#2 0x0000000126c3d283 in node_db::Query::value (this=0x100916bd0, value={> = {val_ = 0x1258013c8}, }, inArray=false, escape=true, precision=-1) at query.cc:1475
#3 0x0000000126c51252 in node_db::Query::Insert (args=@0x7fff5fbff378) at query.cc:484

It seems to be an issue whenever an SQL write query is executed. You can reproduce like so:

$ node
> MYSQL = require('db-mysql')
{ Query: [Function],
Database:
{ [Function]
COLUMN_TYPE_STRING: 0,
COLUMN_TYPE_BOOL: 7,
COLUMN_TYPE_INT: 2,
COLUMN_TYPE_NUMBER: 3,
COLUMN_TYPE_DATE: 4,
COLUMN_TYPE_TIME: 5,
COLUMN_TYPE_DATETIME: 6,
COLUMN_TYPE_TEXT: 1,
COLUMN_TYPE_SET: 8 } }
> mysql = new MYSQL.Database({});
{}
> query = mysql.query().insert('foo', ['foo'], ['bar']).execute();
Segmentation fault: 11

OS: OSX 10.7.2
node.js version: v0.6.8
db-mysql version: 0.7.6
I believe the libmysql version is '16' which translates to 1.6? idk how to find out exactly, but if that's not right and you need more info, I'll do what I can to get it for you.