[lxc-devel] [lxc/master] util: always malloc for setproctitle

tych0 on Github lxc-bot at linuxcontainers.org
Thu Feb 2 08:43:08 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 377 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170202/8975ecc2/attachment.bin>
-------------- next part --------------
From be69ad435d6ef810dad446f380df16c63bcbdc88 Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho.andersen at canonical.com>
Date: Thu, 2 Feb 2017 09:36:31 +0100
Subject: [PATCH] util: always malloc for setproctitle

Closes #1407

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 src/lxc/utils.c | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/src/lxc/utils.c b/src/lxc/utils.c
index 0227c32..24000aa 100644
--- a/src/lxc/utils.c
+++ b/src/lxc/utils.c
@@ -1463,34 +1463,24 @@ int setproctitle(char *title)
 	if (!tmp)
 		return -1;
 
-	i = sscanf(tmp, "%lu %lu %lu %lu %lu %lu %lu",
+	i = sscanf(tmp, "%lu %lu %lu %*u %*u %lu %lu",
 		&start_data,
 		&end_data,
 		&start_brk,
-		&arg_start,
-		&arg_end,
 		&env_start,
 		&env_end);
-	if (i != 7)
+	if (i != 5)
 		return -1;
 
 	/* Include the null byte here, because in the calculations below we
 	 * want to have room for it. */
 	len = strlen(title) + 1;
 
-	/* If we don't have enough room by just overwriting the old proctitle,
-	 * let's allocate a new one.
-	 */
-	if (len > arg_end - arg_start) {
-		void *m;
-		m = realloc(proctitle, len);
-		if (!m)
-			return -1;
-		proctitle = m;
-
-		arg_start = (unsigned long) proctitle;
-	}
+	proctitle = realloc(proctitle, len);
+	if (!proctitle)
+		return -1;
 
+	arg_start = (unsigned long) proctitle;
 	arg_end = arg_start + len;
 
 	brk_val = syscall(__NR_brk, 0);


More information about the lxc-devel mailing list