Skip to content

Commit 001eb63

Browse files
natoscottclaude
andcommitted
Strip control characters from info screen titles
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>
1 parent 6d7b439 commit 001eb63

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

InfoScreen.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ void InfoScreen_drawTitled(InfoScreen* this, const char* fmt, ...) {
5959
memset(&title[COLS - 3], '.', 3);
6060
}
6161

62+
String_stripControlChars(title);
63+
6264
attrset(CRT_colors[METER_TEXT]);
6365
mvhline(0, 0, ' ', COLS);
6466
mvaddstr(0, 0, title);

XUtils.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,19 @@ static inline ssize_t full_write_str(int fd, const char* str) {
131131
return full_write(fd, str, strlen(str));
132132
}
133133

134+
static inline bool Char_isControl(char c) {
135+
return (unsigned char)c < ' ' || c == '\x7F';
136+
}
137+
138+
/* Replace control characters (C0 and DEL) with a safe substitute. */
139+
ATTR_NONNULL
140+
static inline void String_stripControlChars(char* s) {
141+
for (; *s; s++) {
142+
if (Char_isControl(*s))
143+
*s = '?';
144+
}
145+
}
146+
134147
/* Compares floating point values for ordering data entries. In this function,
135148
NaN is considered "less than" any other floating point value (regardless of
136149
sign), and two NaNs are considered "equal" regardless of payload. */

0 commit comments

Comments
 (0)