replace strncopy by memcpy
PATCH 1/1 replace strncopy by memcpy
This patch fixes build with GCC 10.3.0, that fails with warning/error:
'__builtin_strncpy' specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
Destination buffer size is is checked properly, memcpy is equivalent to strncpy here as pointed by Santtu.
This patch replaces my previous one:
"dnsproxy: Suppress GCC warning stringop-overflow"
Lukas
From 3dca8ec863d60a3bfd81baeb56255742c242ad93 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Karas?= <[email protected]>
Date: Fri, 18 Jun 2021 11:09:04 +0200
Subject: [PATCH] replace strncopy by memcpy
Destination buffer size is is checked properly,
but GCC 10.3.0 analysis fails to detect it and prints stringop-overflow warning. Memcpy is equivalent to strncpy here, because ulen = strlen(name) + 1.
--- src/dnsproxy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/dnsproxy.c +1 -1
@@ -1791,7 +1791,7 @@ static char *uncompress(int16_t field_count, char *start, char *end, ulen =strlen (name) +1 ;if ((uptr + ulen) > uncomp_end) goto out; -strncpy (uptr, name, ulen); +memcpy (uptr, name, ulen);debug ("pos %d ulen %d left %d name %s" , pos, ulen, (int )(uncomp_end - (uptr + ulen)), uptr);
Signature · 1 line
2.27.0