All of lore.kernel.org
 help / color / mirror / Atom feed
From: Will Dietz <w@wdtz.org>
To: iwd@lists.01.org
Subject: [PATCH] Don't pass NULL as src to memcpy, even when zero len.
Date: Mon, 28 Oct 2019 14:42:01 -0500	[thread overview]
Message-ID: <20191028194201.12372-1-w@wdtz.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 596 bytes --]

Skip the memcpy when len = 0, definitely don't ignore attempt
to copy X bytes from NULL where X != 0 :).
---
 monitor/main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/monitor/main.c b/monitor/main.c
index 020dba86..41692cd1 100644
--- a/monitor/main.c
+++ b/monitor/main.c
@@ -176,7 +176,8 @@ static size_t rta_add(void *rta_buf, unsigned short type, uint16_t len,
 
 	rta->rta_len = rta_len;
 	rta->rta_type = type;
-	memcpy(RTA_DATA(rta), data, len);
+	if (len)
+		memcpy(RTA_DATA(rta), data, len);
 
 	return RTA_SPACE(len);
 }
-- 
2.24.0-rc1

             reply	other threads:[~2019-10-28 19:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-28 19:42 Will Dietz [this message]
2019-10-28 19:59 ` [PATCH] Don't pass NULL as src to memcpy, even when zero len Denis Kenzior

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=20191028194201.12372-1-w@wdtz.org \
    --to=w@wdtz.org \
    --cc=iwd@lists.01.org \
    /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.