]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Fix snprintf truncation in telnet
authorDimitry Andric <dim@FreeBSD.org>
Thu, 21 Dec 2023 22:35:17 +0000 (23:35 +0100)
committerDimitry Andric <dim@FreeBSD.org>
Sun, 24 Dec 2023 14:01:29 +0000 (15:01 +0100)
commit4f3aa626f614a5ea5cfdfff4f77caa9ec10980bb
tree0f124bfefde1f37deb504028cc72315a265b1d1c
parent4d9951cbb68b76d385264e222e5cf74a993b127e
Fix snprintf truncation in telnet

Building telnet with clang 18 results in the following warning:

  contrib/telnet/telnet/telnet.c:231:5: error: 'snprintf' will always be truncated; specified size is 10, but format string expands to at least 11 [-Werror,-Wformat-truncation]
    231 |     snprintf(temp2, sizeof(temp2), "%c%c%c%c....%c%c", IAC, SB, TELOPT_COMPORT,
|     ^

The temp2 buffer is 10 chars, while the format string also consists of
10 chars. Therefore, snprintf(3) will truncate the last character, 'SE'
(end sub negotation) in this case.

Bump the buffer to 11 chars to avoid truncation.

MFC after: 3 days

(cherry picked from commit c794d188222a4d3414233ff9630d47eedc090fbe)
contrib/telnet/telnet/telnet.c