Fix security issues reported by AFINE Team#2001
Conversation
Limit the variable-length array size in RichString_writeFromWide() and RichString_appendnWideColumns() to prevent stack exhaustion from processes with extremely long command lines (up to ARG_MAX ~2MB). Closes: GHSA-mjc3-mc44-c23f Reported-by: Michał Majchrowicz (AFINE Team) Reported-by: Marcin Wyczechowski (AFINE Team) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Prevent stack buffer underflow in InfoScreen_drawTitled() when the terminal width is 2 columns or fewer, where COLS - 3 produces a negative index into the title VLA. Closes: GHSA-6f53-xw2h-ww59 Reported-by: Michał Majchrowicz (AFINE Team) Reported-by: Marcin Wyczechowski (AFINE Team) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sanitise the title string in InfoScreen_drawTitled() before passing it to mvaddstr(), preventing terminal escape sequence injection via crafted process argv[0]. Adds Char_isControl() and String_stripControlChars() helpers to XUtils for reuse. Closes: GHSA-q64m-h5hc-c4qq Reported-by: Michał Majchrowicz (AFINE Team) Reported-by: Marcin Wyczechowski (AFINE Team) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace the >= 32 byte check with Char_isControl() which also filters DEL (0x7F), consistent with the wide-char path that uses iswprint(). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
WalkthroughThis PR hardens control character handling across the display pipeline by introducing two utility helpers— Poem
Comment |
|
@Explorer09 for security sensitive issues, please keep the signal-to-noise ratio clean. We can follow up with nice-to-have suggestions later, separately, for now we need to focus on only the most clear, minimal, correct fixes that address the issues. Please leave reviewing here for the maintainers (unless you spot an actual bug in these fixes!). Thanks. FWIW, this is what ~30 seconds of trivial AI checking gives - all good feedback: |
I'm confused now. Because the AI didn't report the accurate answer. In UTF-8, byte values 0xC0..0xC1 and 0xF5..0xFF are never valid. Why filter only C0 control characters while other control characters can also potentially cause security issues? I know you guys want to patch the security issue fast, but I expect a better answer such as "this is a temporary measure while a more comprehensive filter can come out later". |
See followup comments inline with code above. |
fasterit
left a comment
There was a problem hiding this comment.
Great work, thank you AFINE team for checking and reporting
BenBE
left a comment
There was a problem hiding this comment.
LGTM.
Regarding Char_isControl we should do a more thorough pass in a follow-up to see if there are related places.
Apart from that, as mentioned, we should aim to get rid of all the VLA in the future.
I did an audit earlier an found no other places FWIW. |
Summary
RichString_writeFromWide()andRichString_appendnWideColumns()to prevent stack exhaustion from processes with very long command lines (GHSA-mjc3-mc44-c23f)InfoScreen_drawTitled()against narrow terminal widths to prevent stack buffer underflow (GHSA-6f53-xw2h-ww59)mvaddstr()to prevent terminal escape sequence injection (GHSA-q64m-h5hc-c4qq)Char_isControl()andString_stripControlChars()helpers to XUtils, and useChar_isControl()in non-wide RichString rendering to also filter DEL (0x7F)All three issues were reported by Michał Majchrowicz and Marcin Wyczechowski of the AFINE Team.
Summary
Addresses three GHSA security issues (GHSA-mjc3-mc44-c23f, GHSA-6f53-xw2h-ww59, GHSA-q64m-h5hc-c4qq) via targeted fixes to VLA handling, buffer bounds checking, and control character sanitization.
Changes
InfoScreen.c (+3/-1): Adds bounds check
COLS >= 3alongside length check before truncating with trailing dots, preventing stack buffer underflow when terminal width is very narrow. Introduces call toString_stripControlChars()to sanitize title strings before passing tomvaddstr(), blocking terminal escape sequence injection.RichString.c (+9/-1): Introduces
RICHSTRING_MAX_WIDE_LENconstant (0x8000 / 32KB) and caps VLA allocations inRichString_writeFromWide()andRichString_appendnWideColumns()to prevent stack exhaustion from processes with extremely long command lines. Replaces simple>= 32printable-byte check withChar_isControl()predicate in non-wide rendering path to also filter DEL character (0x7F), maintaining consistency with wide-character path usingiswprint().XUtils.h (+13/-0): Adds two static inline helpers:
Char_isControl()classifying control characters as those below space or equal to 0x7F, andString_stripControlChars()iterating through mutable strings to replace detected control characters with '?'.Assessment
Implementation is clean and logically organized. All three fixes are properly isolated by concern: VLA bounds in RichString for stack exhaustion, width validation in InfoScreen for buffer underflow, and control character filtering for injection prevention. Helper functions are positioned inline in headers for efficiency. Bounds enforcement uses reasonable limits (32KB for wide-character operations) and consistent filtering logic across code paths.