Skip to content

fix(log): prevent formatter size wrap - #16

Open
Zartharas wants to merge 1 commit into
Monstatek:mainfrom
Zartharas:fix/log-formatter-size-wrap
Open

fix(log): prevent formatter size wrap#16
Zartharas wants to merge 1 commit into
Monstatek:mainfrom
Zartharas:fix/log-formatter-size-wrap

Conversation

@Zartharas

Copy link
Copy Markdown

Summary

Prevent m1_logdb_dyn_vsprintf() from truncating the dynamic buffer size through an 8-bit uint8_t temporary.

For certain oversized formatted outputs, ret_n + 20 can 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:

- uint8_t mem_size;
+ int mem_size;

Validation

  • Independent host reproduction of the upstream size-wrap/repeated-state defect: PASS
  • Corrected host behavior: PASS
  • Paired ARM baseline/fixed builds with Arm GNU 14.2.Rel1: PASS
  • Baseline warnings: 1076
  • Fixed warnings: 1076 (warning_delta=0)
  • Baseline/fixed build errors: 0
  • Firmware artifact size delta: 0 bytes for BIN, CRC BIN, ELF, and HEX
  • ELF memory footprint delta: text=0, data=0, bss=0
  • Cold-rebuilt baseline reproduced the historical WP1 firmware artifacts byte-for-byte
  • Fixed firmware rebuilt twice with byte-identical BIN, CRC BIN, ELF, and HEX artifacts

Provenance

The issue was identified while reviewing reliability work in bedge117/M1, specifically commit 4fa1a463dee5c224cc590eb323806a369ea1b23a (C3.157: wedge-hardening pass ...). The change here was independently reproduced against Monstatek/M1 and reduced to the one-line root-cause correction above rather than copying the larger reference patch.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant