fix(log): prevent formatter size wrap - #16
Open
Zartharas wants to merge 1 commit into
Open
Conversation
m1_logdb_dyn_vsprintf stores the dynamic buffer size in uint8_t. When ret_n + 20 exceeds 255, the value can wrap below the formatter size cap and repeat the same allocation/format cycle. Use int for mem_size so the required size is compared without 8-bit truncation. Validated with an independent host reproduction, paired ARM baseline/fixed builds, zero warning and footprint delta, historical WP1 byte-identical baseline reproduction, and repeatable fixed firmware artifacts. Reference: bedge117/M1 commit 4fa1a46; independently reduced to the minimal one-line root-cause correction.
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.
Summary
Prevent
m1_logdb_dyn_vsprintf()from truncating the dynamic buffer size through an 8-bituint8_ttemporary.For certain oversized formatted outputs,
ret_n + 20can exceed 255 and wrap back below the formatter's size cap. A 240-byte formatted result reproduces the repeated state deterministically:240 + 20 -> 260 -> 4, after which the formatter can repeat the same allocation/format cycle.The fix is intentionally minimal:
Validation
warning_delta=0)text=0,data=0,bss=0Provenance
The issue was identified while reviewing reliability work in
bedge117/M1, specifically commit4fa1a463dee5c224cc590eb323806a369ea1b23a(C3.157: wedge-hardening pass ...). The change here was independently reproduced againstMonstatek/M1and reduced to the one-line root-cause correction above rather than copying the larger reference patch.