Merge pull request #675 from brianc/issues/675
Postgres Native bindings Segfault when querying with empty buffer
This commit is contained in:
commit
6cb49b65e6
@ -3,3 +3,5 @@ node_js:
|
||||
- "0.10"
|
||||
before_script:
|
||||
- node script/create-test-tables.js pg://postgres@127.0.0.1:5432/postgres
|
||||
env:
|
||||
- PGUSER=postgres PGDATABASE=postgres
|
||||
|
@ -876,13 +876,17 @@ private:
|
||||
} else if(val->IsNull()) {
|
||||
paramValues[i] = NULL;
|
||||
} else if(val->IsObject() && Buffer::HasInstance(val)) {
|
||||
char *cHexString = MallocCHexString(val->ToObject());
|
||||
if(!cHexString) {
|
||||
LOG("ArgToCStringArray: OUT OF MEMORY OR SOMETHING BAD!");
|
||||
ReleaseCStringArray(paramValues, i-1);
|
||||
return 0;
|
||||
if(Buffer::Length(val) > 0) {
|
||||
char *cHexString = MallocCHexString(val->ToObject());
|
||||
if(!cHexString) {
|
||||
LOG("ArgToCStringArray: OUT OF MEMORY OR SOMETHING BAD!");
|
||||
ReleaseCStringArray(paramValues, i-1);
|
||||
return 0;
|
||||
}
|
||||
paramValues[i] = cHexString;
|
||||
} else {
|
||||
paramValues[i] = MallocCString(NanNew<String>(""));
|
||||
}
|
||||
paramValues[i] = cHexString;
|
||||
} 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