From ee445dafcb98d1992ffa1ff58c8e0b67a651bd16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trung=20L=C3=AA?= <8@tle.id.au> Date: Thu, 29 Jan 2026 16:43:09 +1100 Subject: [PATCH] Fix misleading strncat usage in RFCMIME.c Replace strncat(buf, str, strlen(str)) with strcat(buf, str). Using strlen(src) as the bound to strncat is pointless - it will always copy the entire source string, making it equivalent to strcat. This also triggers -Wstringop-overflow warnings on modern GCC. Similarly, strncat with literal strings and their exact length (e.g., strncat(buf, "==", 2)) is equivalent to strcat. --- cde/programs/dtcm/dtcm/RFCMIME.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/cde/programs/dtcm/dtcm/RFCMIME.c b/cde/programs/dtcm/dtcm/RFCMIME.c index 951d817aa..57e177923 100644 --- a/cde/programs/dtcm/dtcm/RFCMIME.c +++ b/cde/programs/dtcm/dtcm/RFCMIME.c @@ -1202,7 +1202,7 @@ writeBase64(char * buf, const char * bp, const unsigned long len) enc_char = ((ubp[block] & 0x3) << 4); strncat(buf, &base64_chars[enc_char], 1); - strncat(buf,"==", 2); + strcat(buf, "=="); break; case 2: @@ -1215,7 +1215,7 @@ writeBase64(char * buf, const char * bp, const unsigned long len) enc_char = ((ubp[block + 1] & 0xf) << 2); strncat(buf,&base64_chars[enc_char], 1); - strncat(buf,"=", 1); + strcat(buf, "="); } /* crlf(buf); */ @@ -1533,9 +1533,9 @@ rfc1522cpy(char * buf, const char * value) _tmp1_, NULL, &_tmp2_ ); - strncat(buf,"=?", 2); - strncat(buf,_tmp2_, strlen(_tmp2_)); - strncat(buf,"?q?", 3); + strcat(buf, "=?"); + strcat(buf, _tmp2_); + strcat(buf, "?q?"); free(_tmp1_); free(_tmp2_); @@ -1544,13 +1544,13 @@ rfc1522cpy(char * buf, const char * value) * According to RFC1468, in the Header Field, we should use * B-encoding */ - strncat(buf,"=?", 2); - strncat(buf,charset, strlen(charset)); - strncat(buf,"?b?", 3); + strcat(buf, "=?"); + strcat(buf, charset); + strcat(buf, "?b?"); } else { - strncat(buf,"=?", 2); - strncat(buf,charset, strlen(charset)); - strncat(buf,"?q?", 3); + strcat(buf, "=?"); + strcat(buf, charset); + strcat(buf, "?q?"); } /* @@ -1580,7 +1580,7 @@ rfc1522cpy(char * buf, const char * value) } else writeQPrint( tmp, cur, scan_c - cur, 0 ); - strncat(buf,tmp,strlen(tmp)); + strcat(buf, tmp); strcat(buf,"?="); cur = scan_c - 1; }