errors icon indicating copy to clipboard operation
errors copied to clipboard

Uncaught exceptions on hex char been deliverd to verror.js

Open kobymolcho opened this issue 7 years ago • 7 comments

when creating new restify error with a "%25" as a prefix and than one of the following chars (e,E,f,g,G,d etc...) the application will break with an uncaught exception. it looks like verror uses sprintf, and it encodes "%25" a real "%" delivered as an argument. this end with "Error: next shouldn't be called more than once"

kobymolcho avatar Jun 20 '18 08:06 kobymolcho

Hi @kobymolcho, do you have a sample code snippet here to reproduce the exact exception you are seeing? Anything involving the % does sound sprintf related but want to make sure we're looking at the right thing.

DonutEspresso avatar Jun 20 '18 17:06 DonutEspresso

try this out: server.get('/', function(req, res, next) { var err = new restify.errors.NotFoundError('1234%25d1234'); return next(err); });

kobymolcho avatar Jun 20 '18 17:06 kobymolcho

Thanks! What version of restify-errors are you using?

If you reduce it down to just these two lines, can you confirm the exception you are seeing:

const errs = require('restify-errors');
var err = new errs.NotFoundError('1234%25d1234');
/Users/aliu/Sandbox/test/node_modules/extsprintf/lib/extsprintf.js:97
			throw (jsError(ofmt, convposn, curconv,
			^

Error: format string "1234%25d1234": conversion specifier "%25d" at character 5 has no matching argument (too few arguments passed)

DonutEspresso avatar Jun 20 '18 18:06 DonutEspresso

i'm using 6.4.0, and yes - i can confirm this two lines throws.. node_modules/extsprintf/lib/extsprintf.js:72 throw (new Error('too few args to sprintf'));

kobymolcho avatar Jun 20 '18 18:06 kobymolcho

Thanks for the confirmation. This is expected behavior - you can work around it for now:

var err = new errs.NotFoundError('%s', '1234%25d1234');

Alternatively, some work is happening over in joyent/node-verror#57 to allow disabling of printf via a constructor option.

DonutEspresso avatar Jun 21 '18 04:06 DonutEspresso

That's a great tip.. Thank you!

kobymolcho avatar Jun 21 '18 05:06 kobymolcho

As it looks like this was resolved (and behavior was expected), I'll close this ticket now. @kobymolcho let us know if that isn't the case.

DonutEspresso avatar Jul 31 '18 06:07 DonutEspresso