Don't use a plain %s when writing to a buffer
My compiler was understandably concerned about a potential buffer overflow here. I don't think the string could get long enough to cause that to happen, but it's hard to be certain. It's much safer to limit the length of the string so that it fits in the buffer, as done here, and if there really wasn't a problem the change will cause no harm at all. (If there was, the string will be truncated rather than corrupting memory. This code is in showing the config-file version of a status highlight, something where truncated text will probably be obvious to the user.)
This commit is contained in:
@@ -3163,7 +3163,9 @@ status_hilites_viewall()
|
||||
datawin = create_nhwindow(NHW_TEXT);
|
||||
|
||||
while (hlstr) {
|
||||
Sprintf(buf, "OPTIONS=hilite_status: %s", hlstr->str);
|
||||
Sprintf(buf, "OPTIONS=hilite_status: %.*s",
|
||||
(int)(BUFSZ - sizeof "OPTIONS=hilite_status: " - 1),
|
||||
hlstr->str);
|
||||
putstr(datawin, 0, buf);
|
||||
hlstr = hlstr->next;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user