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

Critical bug: buffer overflow in catch's handling of arguments #665

Closed
netheril96 opened this issue May 22, 2016 · 6 comments
Closed

Critical bug: buffer overflow in catch's handling of arguments #665

netheril96 opened this issue May 22, 2016 · 6 comments

Comments

@netheril96
Copy link

Compiling with address sanitizer that comes with the latest gcc or clang, we can find that the latest catch has buffer overflow when parsing arguments. Here is a screenshot:

screenshot

Both v1.5.4 and v1.5.3 have the same bug. I have not tested earlier versions.

@netheril96
Copy link
Author

netheril96 commented May 26, 2016

Specifically, in Parser::handleOpt, the original code is

if( std::string( ":=\0", 5 ).find( c ) == std::string::npos )

The length of string literal is only 3, yet the constructor reads 5 chars out of it.

Similarly, in Parser::handlePositional,

if( inQuotes || std::string( "\0", 3 ).find( c ) == std::string::npos )

The constructor reads 3 characters out of length-1 string literal.

Both of these cases result in undefined behavior.

@ianmacs
Copy link

ianmacs commented Jun 8, 2016

I agree this is a bug. It was introduced in v1.5.2.

suggest these fixes:
if (c != ':' && c != '=' && c != '\0')
if (inQuotes || c != '\0')

@rioderelfte
Copy link

I have already created a pull request in Clara to fix this problem: catchorg/Clara#17

@philsquared
Copy link
Collaborator

Ouch! Sorry about that. I'll try and get this sorted (in both code bases) later today - thanks for bringing it up (and @rioderelfte for the PR)

@ianmacs
Copy link

ianmacs commented Jun 12, 2016

Thanks for fixing this in v1.5.6.
This bug can be closed.

@horenmar
Copy link
Member

Since this was fixed, I am closing the issue.

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

5 participants