Skip to content

Undefined query parameters causes crash #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bdunavant opened this issue Oct 13, 2011 · 5 comments
Closed

Undefined query parameters causes crash #55

bdunavant opened this issue Oct 13, 2011 · 5 comments

Comments

@bdunavant
Copy link
Contributor

If you pass an undefined value as a parameter to a query it crashes when trying to bind. Unfortunately with a stack trace that makes it very difficult to find your error (at least without putting console.logs inside of _pulseQuery to figure out which query is running).

Not sure what the correct solution would be here. Treat it as NULL? Throw an error?

Test case:

var pg = require('pg');
var conString = "tcp://user:pass@localhost/postgres";
pg.connect( conString, function(err, client) {
client.query("select $1 as foo", [ undefined ], function(err, result) {
console.log(result.rows[0].foo);
});
});

Crash output:

TypeError: Cannot call method 'toString' of undefined
at [object Object].bind (/Users/brian/node_modules/pg/lib/connection.js:138:17)
at [object Object].prepare (/Users/brian/node_modules/pg/lib/query.js:136:14)
at [object Object].submit (/Users/brian/node_modules/pg/lib/query.js:95:10)
at [object Object]._pulseQueryQueue (/Users/brian/node_modules/pg/lib/client.js:140:24)
at [object Object].query (/Users/brian/node_modules/pg/lib/client.js:164:8)
at assign_pending_items (/Users/brian/lucre/app.js:291:8)
at /Users/brian/lucre/app.js:213:3
at callbacks (/Users/brian/node_modules/express/lib/router/index.js:272:11)
at requireLogin (/Users/brian/lucre/app.js:46:3)
at callbacks (/Users/brian/node_modules/express/lib/router/index.js:272:11)

@bdunavant
Copy link
Contributor Author

For what it's worth, for inputs I'd treat undefined as a null value. It also makes it a one line change to fix at that point I believe :)

@brianc
Copy link
Owner

brianc commented Oct 14, 2011

I think undefined should probably be treated as null. I've bit bitten by
this same issue in some apps I've developed with node-postgres. Interested
in forking & pull-requesting? I've not I'll pound this out myself, but
might be fun for you, yeah? ;)

On Wed, Oct 12, 2011 at 9:46 PM, Brian Dunavant <
[email protected]>wrote:

If you pass an undefined value as a parameter to a query it crashes when
trying to bind. Unfortunately with a stack trace that makes it very
difficult to find your error (at least without putting console.logs inside
of _pulseQuery to figure out which query is running).

Not sure what the correct solution would be here. Treat it as NULL?
Throw an error?

Test case:

var pg = require('pg');
var conString = "tcp://user:pass@localhost/postgres";
pg.connect( conString, function(err, client) {
client.query("select $1 as foo", [ undefined ], function(err, result) {
console.log(result.rows[0].foo);
});
});

Crash output:

TypeError: Cannot call method 'toString' of undefined
at [object Object].bind
(/Users/brian/node_modules/pg/lib/connection.js:138:17)
at [object Object].prepare
(/Users/brian/node_modules/pg/lib/query.js:136:14)
at [object Object].submit
(/Users/brian/node_modules/pg/lib/query.js:95:10)
at [object Object]._pulseQueryQueue
(/Users/brian/node_modules/pg/lib/client.js:140:24)
at [object Object].query
(/Users/brian/node_modules/pg/lib/client.js:164:8)
at assign_pending_items (/Users/brian/lucre/app.js:291:8)
at /Users/brian/lucre/app.js:213:3
at callbacks
(/Users/brian/node_modules/express/lib/router/index.js:272:11)
at requireLogin (/Users/brian/lucre/app.js:46:3)
at callbacks
(/Users/brian/node_modules/express/lib/router/index.js:272:11)

Reply to this email directly or view it on GitHub:
#55

@bdunavant
Copy link
Contributor Author

Sure! Sounds like fun.

@bdunavant
Copy link
Contributor Author

The response for this is in issue #56 which got created when I submitted the code. Sorry, didn't know how to make it reference this issue.

@bdunavant
Copy link
Contributor Author

Closing since this fix was merged in #56

brianc added a commit that referenced this issue Dec 20, 2019
* Bump version of pg-cursor

This includes fixes in [email protected].  I've relaxed semver a touch so I don't have to release a new version here just for patch changes to pg-cursor.

* Pass options to pg-cursor

fixes #55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants