Fix for empty buffer segfault in native bindings
This commit is contained in:
parent
587cb0a2c8
commit
f088442570
@ -876,6 +876,7 @@ private:
|
||||
} else if(val->IsNull()) {
|
||||
paramValues[i] = NULL;
|
||||
} else if(val->IsObject() && Buffer::HasInstance(val)) {
|
||||
if(Buffer::Length(val) > 0) {
|
||||
char *cHexString = MallocCHexString(val->ToObject());
|
||||
if(!cHexString) {
|
||||
LOG("ArgToCStringArray: OUT OF MEMORY OR SOMETHING BAD!");
|
||||
@ -883,6 +884,9 @@ private:
|
||||
return 0;
|
||||
}
|
||||
paramValues[i] = cHexString;
|
||||
} else {
|
||||
paramValues[i] = MallocCString(NanNew<String>(""));
|
||||
}
|
||||
} else {
|
||||
//a paramter was not a string
|
||||
LOG("Parameter not a string or buffer");
|
||||
|
28
test/integration/gh-issues/675-tests.js
Normal file
28
test/integration/gh-issues/675-tests.js
Normal file
@ -0,0 +1,28 @@
|
||||
var helper = require('../test-helper');
|
||||
var assert = require('assert');
|
||||
|
||||
helper.pg.connect(function(err, client, done) {
|
||||
if (err) throw err;
|
||||
|
||||
var c = 'CREATE TEMP TABLE posts (body TEXT)';
|
||||
|
||||
client.query(c, function(err) {
|
||||
if (err) throw err;
|
||||
|
||||
c = 'INSERT INTO posts (body) VALUES ($1) RETURNING *';
|
||||
|
||||
var body = new Buffer('foo');
|
||||
client.query(c, [body], function(err) {
|
||||
if (err) throw err;
|
||||
|
||||
body = new Buffer([]);
|
||||
client.query(c, [body], function(err, res) {
|
||||
done();
|
||||
|
||||
if (err) throw err;
|
||||
assert.equal(res.rows[0].body, '')
|
||||
helper.pg.end();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user