Skip to content

Commit 544880e

Browse files
natoscottclaude
andcommitted
Cap VLA length in RichString wide-character functions
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>
1 parent b7f9df9 commit 544880e

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

RichString.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ in the source distribution for its full text.
2121

2222
#define charBytes(n) (sizeof(CharType) * (n))
2323

24+
#define RICHSTRING_MAX_WIDE_LEN 0x8000
25+
2426
static void RichString_extendLen(RichString* this, size_t len) {
2527
if (this->chptr == this->chstr) {
2628
// String is in internal buffer
@@ -101,6 +103,9 @@ static inline int RichString_writeFromWide(RichString* this, int attrs, const ch
101103
if (len < 1)
102104
return 0;
103105

106+
if (len > RICHSTRING_MAX_WIDE_LEN)
107+
len = RICHSTRING_MAX_WIDE_LEN;
108+
104109
wchar_t data[len];
105110
len = mbstowcs_nonfatal(data, data_c, len);
106111
if (len <= 0)
@@ -116,6 +121,9 @@ static inline int RichString_writeFromWide(RichString* this, int attrs, const ch
116121
}
117122

118123
int RichString_appendnWideColumns(RichString* this, int attrs, const char* data_c, size_t len, int* columns) {
124+
if (len > RICHSTRING_MAX_WIDE_LEN)
125+
len = RICHSTRING_MAX_WIDE_LEN;
126+
119127
wchar_t data[len];
120128
len = mbstowcs_nonfatal(data, data_c, len);
121129
if (len <= 0)

0 commit comments

Comments
 (0)