archive mirror
 help / color / mirror / Atom feed
From: "Lukáš Karas" <>
Subject: [PATCH] replace strncopy by memcpy
Date: Fri, 18 Jun 2021 11:27:07 +0200	[thread overview]
Message-ID: <1834096.Zu5ogFxJLL@latitudemachine> (raw)

[-- Attachment #1.1: Type: text/plain, Size: 390 bytes --]

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"


[-- Attachment #1.2: 0001-replace-strncopy-by-memcpy.patch --]
[-- Type: text/x-patch, Size: 956 bytes --]

From 3dca8ec863d60a3bfd81baeb56255742c242ad93 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Karas?= <>
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(-)

diff --git a/src/dnsproxy.c b/src/dnsproxy.c
index 38dbdd71..4b65b379 100644
--- a/src/dnsproxy.c
+++ b/src/dnsproxy.c
@@ -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);

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

             reply	other threads:[~2021-06-18  9:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-18  9:27 Lukáš Karas [this message]
2021-06-18 12:38 [PATCH] replace strncopy by memcpy VAUTRIN Emmanuel (Canal Plus Prestataire)
2021-06-18 17:53 ` Santtu Lakkala
2021-06-21  7:00   ` Daniel Wagner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1834096.Zu5ogFxJLL@latitudemachine \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).