fix off-by-one write in proc/cpuinfo hardware/revision parse#414
fix off-by-one write in proc/cpuinfo hardware/revision parse#414soma0212 wants to merge 1 commit into
Conversation
|
Hi @soma0212! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
In
parse_line(src/arm/linux/cpuinfo.c) the Hardware and Revision handlers null-terminate withstate->hardware[value_length] = '\0'in the branch taken when the value fits. But the length guard uses> CPUINFO_HARDWARE_VALUE_MAX(and> CPUINFO_REVISION_VALUE_MAX), so a value whose length is exactly the max still takes that branch. Those destinations are exactly MAX bytes (64 and 9), so aHardwareline with a 64-byte value, or aRevisionline with a 9-byte value, writes the terminator one byte past the buffer.Change both comparisons to
>=so an equal-length value goes through the truncation path instead. That leaves the buffer full and unterminated, which is already the contract downstream code relies on (the chipset decoders read these fields withstrnlen(buf, MAX)), so keeping the bound at the write site is enough and no consumer needs to change.