-
Notifications
You must be signed in to change notification settings - Fork 1.3k
TGNumberEntry string length checks are inaccurate/dangerous. #17334
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
Comments
Additional warnings by clang-tidy:
|
I had a look at the code and I was left in awe by how abysmally it is written. Many of the conversion functions are redundant at best and plain wrong at worst, moreover they are written with no regards to efficiency (or memory safety) at all. Here is a taste of it (comments added by me): for (UInt_t i = 0; i < strlen(p); i++) { // recomputing strlen every time
if (isdigit(*p)) { // always testing the same character??
found++; // doesn't look like it's doing what it would like to do
}
}
while (found < digits) {
// coverity[secure_coding] // what??
// again, recomputing strlen every time
// also, unsafe function being used (with no bounds checking)
// also, this whole loop is redudant (why do 1 chr at a time?)
strcpy(p + strlen(p), "0");
found++;
} Is this code actually used? Can we deprecate and remove it? If not, we should really rewrite most of this stuff... |
I use this code actively for my GUI classes, please don't deprecate the class :). (Feel free though to remove useless parts within it) |
Uh oh!
There was an error while loading. Please reload this page.
As seen in #16913, there is some attempt to guarantee that there will be no write past the end of buffer in the string manipulations. However in several places, it fall short (literally or maybe missing documentation).
We should consider replacing the fixed size buffer or improving the bound checks.
Namely the routines seems to assume that the buffer has a fixed length of 256 but in several place, the buffer is offset compare to its actual beginning.
StrInt(char *text, Long_t i, Int_t digits)
hard-codes the length 250 for its input buffer, we should pass the actual length left there. In particular lineTGNumberEntry.cxx:310
andTGNumberEntry.cxx:316
needs to be updated.We should also review the rest
TGNumberEntry.cxx
for similar problematic patterns.The text was updated successfully, but these errors were encountered: