-
Notifications
You must be signed in to change notification settings - Fork 273
Fix endless loop bug #979
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
Fix endless loop bug #979
Conversation
src/util/irep_serialization.cpp
Outdated
@@ -327,7 +327,7 @@ irep_idt irep_serializationt::read_gb_string(std::istream &in) | |||
char c; | |||
size_t length=0; | |||
|
|||
while((c = in.get()) != 0) | |||
while(in.good() && (c = in.get()) != 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't an error be reported if such a string without 0-termination is encountered?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tested, original problem is solved with this
error reporting would be nice, but this is from fuzzed binary GOTO, so it is very unlikely to appear in the wild
This patch would move the status from denial-of-service (not great, but low risk of exposing private data) to possibly arbitrary crashes at a later stage that may include buffer overflows. Error detection on invalid input MUST happen as early as possible. |
@tautschnig I see your point, I agree, the error should be detected here and execution should not be continued in this situation. |
src/util/irep_serialization.cpp
Outdated
{ | ||
if(!in.good()) | ||
{ | ||
throw irep_serialization_errort("gb string is not null-terminated"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems Visual Studio doesn't like this. Please just throw the C string, no need for irep_serialization_errort
at this point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to fix the exception constructor than to throw a char star though surely?
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#e14-use-purpose-designed-user-defined-types-as-exceptions-not-built-in-types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not until #911 is merged, or you change all other 1583 uses of throw
without a user-defined type.
d2b6aac
to
aee7578
Compare
src/util/irep_serialization.cpp
Outdated
size_t length=0; | ||
|
||
while((c = in.get()) != 0) | ||
while(char c = in.get()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spacing around =
src/util/irep_serialization.cpp
Outdated
@@ -14,6 +14,10 @@ Date: May 2007 | |||
#include "irep_serialization.h" | |||
#include "string_hash.h" | |||
|
|||
irep_serialization_errort::irep_serialization_errort( | |||
const std::string &error) | |||
: std::runtime_error(error) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coding style for :
ea3429d
to
d7afb39
Compare
src/util/irep_serialization.cpp
Outdated
size_t length=0; | ||
|
||
while((c=static_cast<char>(in.get()))!=0) | ||
{ | ||
if(!in.good()) | ||
{ | ||
throw irep_serialization_errort("gb string is not null-terminated"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'gb' is not very user friendly.
Throw if input format is incorrect
@peterschrammel Could you please review whether you are happy with the current state? |
@peterschrammel ping? |
Fixes #543