[lxc-devel] [lxc/master] tools: s/strncpy()/memcpy()/g

brauner on Github lxc-bot at linuxcontainers.org
Fri May 11 14:00:13 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 366 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180511/0ada645f/attachment.bin>
-------------- next part --------------
From 50c6bb6b74d0414bc1b3bd5395b2bad6009a017d Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Fri, 11 May 2018 15:56:58 +0200
Subject: [PATCH 1/2] Revert "tools: s/strncpy()/strlcpy()/g"

This reverts commit 2ec47d5149e73db97f7877d06d67cb11421097bb.

First, I forgot to actually replace strncpy() with strlcpy(). Second, we don't
want to \0-terminate since this is an abstract unix socket and this is not
required. Instead, let's simply use memcpy() which is more correct and also
silences gcc-8.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/Makefile.am         | 4 ----
 src/lxc/tools/lxc_monitor.c | 4 ----
 2 files changed, 8 deletions(-)

diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am
index ba4993cbd..923c43cab 100644
--- a/src/lxc/Makefile.am
+++ b/src/lxc/Makefile.am
@@ -290,10 +290,6 @@ if ENABLE_TOOLS
 if !HAVE_GETSUBOPT
 lxc_copy_SOURCES += tools/include/getsubopt.c tools/include/getsubopt.h
 endif
-
-if !HAVE_STRLCPY
-lxc_monitor_SOURCES += ../include/strlcpy.c ../include/strlcpy.h
-endif
 endif
 
 if ENABLE_COMMANDS
diff --git a/src/lxc/tools/lxc_monitor.c b/src/lxc/tools/lxc_monitor.c
index ded6f1f38..050b5519b 100644
--- a/src/lxc/tools/lxc_monitor.c
+++ b/src/lxc/tools/lxc_monitor.c
@@ -47,10 +47,6 @@
 #include "arguments.h"
 #include "tool_utils.h"
 
-#ifndef HAVE_STRLCPY
-#include "include/strlcpy.h"
-#endif
-
 static bool quit_monitord;
 
 static int my_parser(struct lxc_arguments* args, int c, char* arg)

From d96a98469176ab6064583331cab9f002632a4586 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Fri, 11 May 2018 15:58:33 +0200
Subject: [PATCH 2/2] tools: s/strncpy()/memcpy()/

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/tools/lxc_monitor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lxc/tools/lxc_monitor.c b/src/lxc/tools/lxc_monitor.c
index 050b5519b..abc8a233a 100644
--- a/src/lxc/tools/lxc_monitor.c
+++ b/src/lxc/tools/lxc_monitor.c
@@ -319,7 +319,7 @@ static int lxc_abstract_unix_connect(const char *path)
 		return -1;
 	}
 	/* addr.sun_path[0] has already been set to 0 by memset() */
-	strncpy(&addr.sun_path[1], &path[1], strlen(&path[1]));
+	memcpy(&addr.sun_path[1], &path[1], strlen(&path[1]));
 
 	ret = connect(fd, (struct sockaddr *)&addr,
 		      offsetof(struct sockaddr_un, sun_path) + len + 1);


More information about the lxc-devel mailing list