[lxc-devel] [lxc/master] macro: calculate buffer lengths correctly

brauner on Github lxc-bot at linuxcontainers.org
Fri Aug 31 22:54:59 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180831/2b7fc9d3/attachment.bin>
-------------- next part --------------
From 54dcfd8160056ba7da311da8d3c2cdce652cb7e5 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 1 Sep 2018 00:14:06 +0200
Subject: [PATCH 1/2] commands: assign before converting to pointer

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/commands.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/lxc/commands.c b/src/lxc/commands.c
index f6a9e4fda..e57a64f33 100644
--- a/src/lxc/commands.c
+++ b/src/lxc/commands.c
@@ -402,8 +402,10 @@ pid_t lxc_cmd_get_init_pid(const char *name, const char *lxcpath)
 static int lxc_cmd_get_init_pid_callback(int fd, struct lxc_cmd_req *req,
 					 struct lxc_handler *handler)
 {
+	intmax_t pid = handler->pid;
+
 	struct lxc_cmd_rsp rsp = {
-		.data = INTMAX_TO_PTR(handler->pid)
+		.data = INTMAX_TO_PTR(pid)
 	};
 
 	return lxc_cmd_rsp_send(fd, &rsp);

From 7fae557dbe5a6fe2c7ab7d5bc8368f13bf772b50 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 1 Sep 2018 00:53:33 +0200
Subject: [PATCH 2/2] macro: calculate buffer lengths correctly

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/macro.h | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/lxc/macro.h b/src/lxc/macro.h
index 96d737267..ef4ac6d11 100644
--- a/src/lxc/macro.h
+++ b/src/lxc/macro.h
@@ -155,12 +155,29 @@
  *                +
  * \0           =    1
  */
-#define LXC_PROC_PID_FD_LEN (6 + INTTYPE_TO_STRLEN(pid_t) + 4 + INTTYPE_TO_STRLEN(int) + 1)
-
-/* /proc/pid-to-str/status\0 = (5 + INTTYPE_TO_STRLEN(pid_t) + 7 + 1) */
+#define LXC_PROC_PID_FD_LEN \
+	(6 + INTTYPE_TO_STRLEN(pid_t) + 4 + INTTYPE_TO_STRLEN(int) + 1)
+
+/* /proc/        = 6
+ *               +
+ * <pid-as-str>  = INTTYPE_TO_STRLEN(pid_t)
+ *               +
+ * /status       = 7
+ *               +
+ * \0            = 1
+ */
 #define LXC_PROC_STATUS_LEN (5 + INTTYPE_TO_STRLEN(pid_t) + 7 + 1)
 
-/* /proc/pid-to-str/attr/current = (5 + INTTYPE_TO_STRLEN(pid_t) + 7 + 1) */
+/* /proc/        = 6
+ *               +
+ * <pid-as-str>  = INTTYPE_TO_STRLEN(pid_t)
+ *               +
+ * /attr/        = 6
+ *               +
+ * /current      = 8
+ *               +
+ * \0            = 1
+ */
 #define LXC_LSMATTRLEN (5 + INTTYPE_TO_STRLEN(pid_t) + 7 + 1)
 
 #define LXC_CMD_DATA_MAX (MAXPATHLEN * 2)


More information about the lxc-devel mailing list