All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Lukáš Karas" <lukas.karas@centrum.cz>
To: connman@lists.linux.dev
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"

Lukas

[-- 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?= <lukas.karas@centrum.cz>
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);
-- 
2.27.0


[-- 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]
  -- strict thread matches above, loose matches on Subject: below --
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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

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

  git send-email \
    --in-reply-to=1834096.Zu5ogFxJLL@latitudemachine \
    --to=lukas.karas@centrum.cz \
    --cc=connman@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.