Repository navigation
Conversation
Contributor
|
There should probably be a trac ticket for this PR. Please create it, or ask us to create it. Then the PR title should be updated. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Platform::loadFromXmlDocument reads char_bit and the type sizes from a
--platformXML file without a range check, while the*_bitmembers they are multiplied into arestd::uint8_t. A file with char_bit 32 and<int>8</int>makes int_bit 32 * 8 == 256, which truncates to 0, and a char_bit or a size of 0 gives a zero width directly;Platform::min_value()/max_value()then evaluate1LL << (bit - 1)with bit 0 and shift by -1, andCheckTypeImpl::checkIntegerOverflowshifts bybits - 1== 0xffffffff. Theassert(bit > 0)in those helpers only fires in a debug build, so a release build keeps analysing the code with bogus type limits. The values are now validated where the file is read, so such a file is rejected with the existing "unrecognized platform" error, the same as a non-numeric value already is.I verified this with a UBSan build. Running
cppcheck --platform=p.xml --enable=all t.con a platform file with char_bit 32 and<int>8</int>reported "shift exponent -1 is negative" at platform.h:52 and :59, "shift exponent 4294967295 is too large for 64-bit type" at checktype.cpp:200 and "shift exponent -1 is negative" at vf_common.cpp:370 before the change, and after it the file is rejected with no sanitizer output. Everything in platforms/ and the built-in platform types still load, the full testrunner passes, and both changed files are clean under selfcheck.One behaviour change worth calling out: valid_config_file_4 asserted that a platform file with char_bit and every size set to 0 loads successfully, which is the case this rejects, so it is now invalid_config_file_3. invalid_config_file_4 covers the char_bit and sizeof product that does not fit.
Could one of you create a trac ticket for this? I will update the title to reference it.