Fix for empty buffer segfault in native bindings
This commit is contained in:
parent
587cb0a2c8
commit
f088442570
@ -876,13 +876,17 @@ private:
|
|||||||
} else if(val->IsNull()) {
|
} else if(val->IsNull()) {
|
||||||
paramValues[i] = NULL;
|
paramValues[i] = NULL;
|
||||||
} else if(val->IsObject() && Buffer::HasInstance(val)) {
|
} else if(val->IsObject() && Buffer::HasInstance(val)) {
|
||||||
char *cHexString = MallocCHexString(val->ToObject());
|
if(Buffer::Length(val) > 0) {
|
||||||
if(!cHexString) {
|
char *cHexString = MallocCHexString(val->ToObject());
|
||||||
LOG("ArgToCStringArray: OUT OF MEMORY OR SOMETHING BAD!");
|
if(!cHexString) {
|
||||||
ReleaseCStringArray(paramValues, i-1);
|
LOG("ArgToCStringArray: OUT OF MEMORY OR SOMETHING BAD!");
|
||||||
return 0;
|
ReleaseCStringArray(paramValues, i-1);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
paramValues[i] = cHexString;
|
||||||
|
} else {
|
||||||
|
paramValues[i] = MallocCString(NanNew<String>(""));
|
||||||
}
|
}
|
||||||
paramValues[i] = cHexString;
|
|
||||||
} else {
|
} else {
|
||||||
//a paramter was not a string
|
//a paramter was not a string
|
||||||
LOG("Parameter not a string or buffer");
|
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