Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 24 Dec 2023 14:03:53 GMT
From:      Dimitry Andric <dim@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 9734bad3611c - stable/12 - Fix snprintf truncation in telnet
Message-ID:  <202312241403.3BOE3rZP057748@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by dim:

URL: https://cgit.FreeBSD.org/src/commit/?id=9734bad3611c291798727ae9020f876304d4e849

commit 9734bad3611c291798727ae9020f876304d4e849
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2023-12-21 22:35:17 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2023-12-24 14:01:35 +0000

    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 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/telnet/telnet/telnet.c b/contrib/telnet/telnet/telnet.c
index b6b2432ef3ec..a98dad499c7b 100644
--- a/contrib/telnet/telnet/telnet.c
+++ b/contrib/telnet/telnet/telnet.c
@@ -208,7 +208,7 @@ unsigned char ComPortBaudRate[256];
 void
 DoBaudRate(char *arg)
 {
-    char *temp, temp2[10];
+    char *temp, temp2[11];
     int i;
     uint32_t baudrate;
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202312241403.3BOE3rZP057748>