-
Notifications
You must be signed in to change notification settings - Fork 342
[All] Security: fix overflows #5901
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
base: master
Are you sure you want to change the base?
[All] Security: fix overflows #5901
Conversation
…reading and writing same buffer). Fixed: sscanf(buf, "%*127s %127s", matName); Breaking down the format: - %*127s - The * is the assignment suppression modifier. It means "read up to 127 chars but discard them (don't store)". This skips the first word (like "newmtl") - %127s - Read the second word (the material name), limited to 127 chars, store in matName So if buf contains "newmtl MyMaterial\n": - %*127s reads and discards "newmtl" - %127s reads "MyMaterial" into matName The 127 limit prevents buffer overflow since matName is 128 bytes (127 chars + null terminator).
… buffer overflows from size calculation wraparound
cbcd999 to
e942da9
Compare
|
[ci-build][with-all-tests] |
| result.resize(length); | ||
| for (int i = 0; i < length; i++) | ||
| result[i] = alphanum[rand() % length]; | ||
| result[i] = alphanum[rand() % alphanum.size()]; |
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.
😮💨
| inline bool wouldOverflowCompliance(unsigned int a, unsigned int b) | ||
| { | ||
| if (a == 0 || b == 0) return false; | ||
| return a > std::numeric_limits<unsigned int>::max() / b; | ||
| } | ||
| } |
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.
Yeah, not impressed... Why not in the meantime increase the size of the variable ? unsigned long ?
| vecString vLine; | ||
|
|
||
| char *l = new char[line.size()]; | ||
| char *l = new char[line.size() + 1]; |
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.
For the \0 char ?
| mat->name = buf; | ||
| { | ||
| char matName[128] = {0}; | ||
| sscanf(buf, "%*127s %127s", matName); |
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.
Ok I don't understand this code.
| if (lines.empty()) | ||
| { | ||
| m.resize(0, 0); | ||
| if( in.rdstate() & std::ios_base::eofbit ) { in.clear(); } | ||
| return in; | ||
| } | ||
|
|
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.
Unecessary quick return... To be removed IMO
| { | ||
| template<typename Index> | ||
| bool wouldOverflowBlock(Index a, Index b) | ||
| { | ||
| if (a <= 0 || b <= 0) return false; | ||
| return a > std::numeric_limits<Index>::max() / b; | ||
| } |
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.
Many definitions of this same function, why not put it in a util file somewhere ?
|
|
||
| namespace | ||
| { | ||
| template<typename Index> |
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.
SAme, could be replaced by a call to the util method with b=3
Different overflows risk were not checked,
and one array access is a bug (in BaseContactMapper)
[with-all-tests]
By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).
Reviewers will merge this pull-request only if