fix(store): clamp ADR render cursor to prevent stack overflow#1175
Open
SEPURI-SAI-KRISHNA wants to merge 1 commit into
Open
fix(store): clamp ADR render cursor to prevent stack overflow#1175SEPURI-SAI-KRISHNA wants to merge 1 commit into
SEPURI-SAI-KRISHNA wants to merge 1 commit into
Conversation
Signed-off-by: SEPURI-SAI-KRISHNA <saik20533@gmail.com>
Owner
|
Thanks for the reproduce-first hardening fix. Triage is complete: this is a high-priority |
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.
What does this PR do?
Fixes a stack out-of-bounds write (CWE-787) in
adr_render_section(
src/store/store.c), the helpercbm_adr_renderuses to concatenate ADRsections into a fixed 16 KB stack buffer (
buf[ST_MAX_DEGREE * ST_GROWTH]).The cursor was advanced by the return value of
snprintf:snprintfreturns the number of bytes it would have written, so once theaccumulated sections exceed
buf_sz,posmoves past the end. On the nextsection
buf + pospoints past the buffer andbuf_sz - pos(anintsubtraction) goes negative, converting to a huge
size_t— sosnprintfwrites out of bounds.
The fix clamps
posinto[0, buf_sz - 1]after every write, so eachsnprintfreceives a positive size and the returned cursor never escapes thebuffer. This mirrors the clamping already done by
http_appendfinsrc/ui/http_server.cand the sibling accumulators instore.c(
search_build_exclude_labels,bfs_build_types_clause).Reproduced first (ASan, before the fix):
After the fix the full
store_archsuite (53 tests) passes with no sanitizererrors.
Adds a regression test
adr_render_oversized_sections_no_overflowthat sizesthree sections so the cursor lands exactly
buf_sz + 8after the secondsection — the third section then performs the first out-of-bounds write right
at the buffer tail (ASan redzone), making the failure deterministic.
Note on scope
cbm_adr_render/cbm_store_adr_update_sectionsare exported instore.hand exercised by the test suite, but currently have no production caller — the
manage_adrMCP tool and the UI/api/adrendpoint both persist raw contentvia
cbm_store_adr_store. So this is a latent defect in exported API ratherthan a live remote overflow; the fix hardens the renderer before anything
wires up the section-merge path.
Checklist
git commit -s) — required, CI rejectsunsigned commits (DCO, see CONTRIBUTING.md)
make -f Makefile.cbm test)make -f Makefile.cbm lint-ci)