Skip to content

Commit 76b2e01

Browse files
natoscottclaude
andcommitted
Filter C1 control characters in addition to C0 and DEL
Hardening follow-up: extend control character filtering to also catch C1 controls (U+0080-U+009F), which are encoded as two-byte UTF-8 sequences starting with 0xC2. Related-to: GHSA-q64m-h5hc-c4qq Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b83a55b commit 76b2e01

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

XUtils.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,20 @@ static inline bool Char_isControl(char c) {
135135
return (unsigned char)c < ' ' || c == '\x7F';
136136
}
137137

138-
/* Replace control characters (C0 and DEL) with a safe substitute. */
138+
static inline bool Char_isC1Control(char c, char next) {
139+
return (unsigned char)c == 0xC2 && (unsigned char)next >= 0x80 && (unsigned char)next <= 0x9F;
140+
}
141+
142+
/* Replace control characters (C0, DEL, and C1) with a safe substitute. */
139143
ATTR_NONNULL
140144
static inline void String_stripControlChars(char* s) {
141-
for (; *s; s++) {
142-
if (Char_isControl(*s))
143-
*s = '?';
145+
for (; s[0]; s++) {
146+
if (Char_isControl(s[0])) {
147+
s[0] = '?';
148+
} else if (Char_isC1Control(s[0], s[1])) {
149+
s[0] = s[1] = '?';
150+
s++;
151+
}
144152
}
145153
}
146154

0 commit comments

Comments
 (0)