onlp/sysi: Make the ONIE IDPROM buffer pass strict_string_checks - #215
Merged
akenliu merged 1 commit intoSep 3, 2026
Merged
Conversation
richardkuo1999
force-pushed
the
6.12-ONSBUSWI-3713
branch
from
September 3, 2026 09:42
7cbc255 to
98c49e9
Compare
richardkuo1999
marked this pull request as draft
September 3, 2026 09:45
onlp_sysi_onie_data_get() allocated exactly 256 bytes and filled every one of them with raw IDPROM content, so the buffer handed to is_valid_tlvinfo_header__() is not guaranteed to be NUL-terminated. strcmp() requires a terminated string, so AddressSanitizer with strict_string_checks=1 reports a heap-buffer-overflow on that call whenever the device carries no zero byte at all - an erased or corrupted IDPROM. Allocating one extra zero byte makes the same run come back clean. Real hardware is not affected: on a programmed IDPROM totallen sits at offsets 9-10, so data[9] is 0x00 for any payload below 256 bytes, and the comparison resolves at index 7 or earlier. The change is about satisfying the strcmp contract under strict checking, not about a failure observed in the field. The read length is deliberately left at 256, so the decoded content and the *size == len guard behave exactly as before. - introduce a local const int len instead of repeating the literal 256 - derive the i2c word-read loop bound from len (len / 2) on as7716-24xc, as7716-32x and as7816-64x, and the byte-read bound on as9516-32d - covers 38 platforms; no behavioural change on any of them
richardkuo1999
force-pushed
the
6.12-ONSBUSWI-3713
branch
from
September 3, 2026 09:48
98c49e9 to
5ffa5af
Compare
richardkuo1999
marked this pull request as ready for review
September 3, 2026 09:49
akenliu
approved these changes
Sep 3, 2026
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.
onlp_sysi_onie_data_get() allocated exactly 256 bytes and filled every one of them with raw IDPROM content, so the buffer handed to is_valid_tlvinfo_header__() is not guaranteed to be NUL-terminated. strcmp() requires a terminated string, so AddressSanitizer with strict_string_checks=1 reports a heap-buffer-overflow on that call whenever the device carries no zero byte at all - an erased or corrupted IDPROM. Allocating one extra zero byte makes the same run come back clean.
Real hardware is not affected: on a programmed IDPROM totallen sits at offsets 9-10, so data[9] is 0x00 for any payload below 256 bytes, and the comparison resolves at index 7 or earlier. The change is about satisfying the strcmp contract under strict checking, not about a failure observed in the field.
The read length is deliberately left at 256, so the decoded content and the *size == len guard behave exactly as before.