Skip to content
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

Uncaught exceptions on hex char been deliverd to verror.js #92

Open
kobymolcho opened this issue Jun 20, 2018 · 7 comments
Open

Uncaught exceptions on hex char been deliverd to verror.js #92

kobymolcho opened this issue Jun 20, 2018 · 7 comments

Comments

@kobymolcho
Copy link

kobymolcho commented Jun 20, 2018

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"

@DonutEspresso
Copy link
Member

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.

@kobymolcho
Copy link
Author

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

@DonutEspresso
Copy link
Member

DonutEspresso commented Jun 20, 2018

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)

@kobymolcho
Copy link
Author

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'));

@DonutEspresso
Copy link
Member

DonutEspresso commented Jun 21, 2018

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 TritonDataCenter/node-verror#57 to allow disabling of printf via a constructor option.

@kobymolcho
Copy link
Author

That's a great tip.. Thank you!

@DonutEspresso
Copy link
Member

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.

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