All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] sheepdog: Replace strncpy() by g_strlcpy()
@ 2018-08-18  2:56 Philippe Mathieu-Daudé
  2018-08-20  9:59 ` David Hildenbrand
  2018-08-20 13:28 ` Paolo Bonzini
  0 siblings, 2 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-08-18  2:56 UTC (permalink / raw)
  To: David Hildenbrand, Howard Spoelstra, Hitoshi Mitake
  Cc: Philippe Mathieu-Daudé,
	qemu-devel, qemu-trivial, Liu Yuan, Jeff Cody, Kevin Wolf,
	Max Reitz, open list:Sheepdog, open list:Sheepdog

Fedora 29 comes with GCC 8.1 which added the 'stringop-truncation' checks.

Replace the strncpy() calls by g_strlcpy() to avoid the following warning:

  block/sheepdog.c: In function 'find_vdi_name':
  block/sheepdog.c:1239:5: error: 'strncpy' specified bound 256 equals
  destination size [-Werror=stringop-truncation]
       strncpy(buf + SD_MAX_VDI_LEN, tag, SD_MAX_VDI_TAG_LEN);
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reported-by: Howard Spoelstra <hsp.cat7@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
See http://lists.nongnu.org/archive/html/qemu-devel/2018-07/msg03723.html

 block/sheepdog.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index b229a664d9..5dc3d0c39e 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -1224,19 +1224,19 @@ static int find_vdi_name(BDRVSheepdogState *s, const char *filename,
     SheepdogVdiReq hdr;
     SheepdogVdiRsp *rsp = (SheepdogVdiRsp *)&hdr;
     unsigned int wlen, rlen = 0;
-    char buf[SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN];
+    /* Ensures that the buffer is zero-filled,
+     * which is desirable since we'll soon be sending those bytes, and
+     * don't want the send_req to read uninitialized data.
+     */
+    char buf[SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN] = { };
 
     fd = connect_to_sdog(s, errp);
     if (fd < 0) {
         return fd;
     }
 
-    /* This pair of strncpy calls ensures that the buffer is zero-filled,
-     * which is desirable since we'll soon be sending those bytes, and
-     * don't want the send_req to read uninitialized data.
-     */
-    strncpy(buf, filename, SD_MAX_VDI_LEN);
-    strncpy(buf + SD_MAX_VDI_LEN, tag, SD_MAX_VDI_TAG_LEN);
+    g_strlcpy(buf, filename, SD_MAX_VDI_LEN);
+    g_strlcpy(buf + SD_MAX_VDI_LEN, tag, SD_MAX_VDI_TAG_LEN);
 
     memset(&hdr, 0, sizeof(hdr));
     if (lock) {
-- 
2.18.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-08-20 13:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-18  2:56 [Qemu-devel] [PATCH] sheepdog: Replace strncpy() by g_strlcpy() Philippe Mathieu-Daudé
2018-08-20  9:59 ` David Hildenbrand
2018-08-20 13:28 ` Paolo Bonzini
2018-08-20 13:33   ` David Hildenbrand

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.