From 27e5f025f12c4e0cdde6f023cd63ca10b75252d8 Mon Sep 17 00:00:00 2001 From: Alex Smith Date: Wed, 1 Nov 2017 15:22:28 +0000 Subject: [PATCH] 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.) --- src/botl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/botl.c b/src/botl.c index 7b06dec87..f0ee33fd0 100644 --- a/src/botl.c +++ b/src/botl.c @@ -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; }