[lxc-devel] [lxc/master] CodeAi fixes: 2 Memory Leaks, 1 Allocation of 0 bytes, and 1 Dead Code

QbitLogic on Github lxc-bot at linuxcontainers.org
Fri Apr 6 19:43:07 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 796 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180406/c85e75f9/attachment.bin>
-------------- next part --------------
From d539ab41a71f098d72512862f1aa20f93ba0612a Mon Sep 17 00:00:00 2001
From: C0deAi <benjamin.bales at assrc.us>
Date: Fri, 6 Apr 2018 11:30:06 -0400
Subject: [PATCH 1/4] CodeAi generated fix for CWE 561 Dead Code

Value stored to 'fd' is never read

Signed-off-by: C0deAi <techsupport at mycode.ai>
---
 src/lxc/cmd/lxc_init.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/lxc/cmd/lxc_init.c b/src/lxc/cmd/lxc_init.c
index a0dabb66a..9168c7878 100644
--- a/src/lxc/cmd/lxc_init.c
+++ b/src/lxc/cmd/lxc_init.c
@@ -150,7 +150,6 @@ static void prevent_forking(void)
 			SYSERROR("Failed to write to \"%s\"", path);
 
 		close(fd);
-		fd = -1;
 		break;
 	}
 

From 70014b83d6f59769d6f121338620c5986067992a Mon Sep 17 00:00:00 2001
From: C0deAi <benjamin.bales at assrc.us>
Date: Fri, 6 Apr 2018 12:07:59 -0400
Subject: [PATCH 2/4] CodeAi generated fix for CWE 131 Allocation of 0 bytes

Call to 'calloc' possibly has an allocation size of 0 bytes

Signed-off-by: C0deAi <techsupport at mycode.ai>
---
 src/lxc/attach.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/lxc/attach.c b/src/lxc/attach.c
index 9a8a836d5..c31caed65 100644
--- a/src/lxc/attach.c
+++ b/src/lxc/attach.c
@@ -38,6 +38,7 @@
 #include <sys/socket.h>
 #include <sys/syscall.h>
 #include <sys/wait.h>
+#include <assert.h>
 
 #include <lxc/lxccontainer.h>
 
@@ -339,6 +340,7 @@ static int lxc_attach_set_environment(struct lxc_proc_context_info *init_ctx,
 			for (count = 0; extra_keep[count]; count++)
 				;
 
+			assert(count != 0 && "count is 0");
 			extra_keep_store = calloc(count, sizeof(char *));
 			if (!extra_keep_store)
 				return -1;

From 045032ea475ee1a3b6ffda0c98247219bcfc6b2c Mon Sep 17 00:00:00 2001
From: C0deAi <benjamin.bales at assrc.us>
Date: Fri, 6 Apr 2018 12:46:53 -0400
Subject: [PATCH 3/4] CodeAi generated fix for CWE 401 Memory Leak

Prevent potential leak of memory pointed to by 's'.

Signed-off-by: C0deAi <techsupport at mycode.ai>
---
 src/lxc/storage/rsync.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/lxc/storage/rsync.c b/src/lxc/storage/rsync.c
index c3080a568..c0f7bccb4 100644
--- a/src/lxc/storage/rsync.c
+++ b/src/lxc/storage/rsync.c
@@ -74,13 +74,20 @@ int lxc_rsync_exec(const char *src, const char *dest)
 
 	ret = snprintf(s, l, "%s", src);
 	if (ret < 0 || (size_t)ret >= l)
+	  {
+	    if (s != NULL) {
+	      free(s);
+	      s = NULL;
+	    }
 		return -1;
+	  }
 
 	s[l - 2] = '/';
 	s[l - 1] = '\0';
 
 	execlp("rsync", "rsync", "-aHXS", "--delete", s, dest, (char *)NULL);
 	free(s);
+	s = NULL;
 	return -1;
 }
 

From 2ef7f80c3b44686a64b853b676ee48663321ab0d Mon Sep 17 00:00:00 2001
From: C0deAi <benjamin.bales at assrc.us>
Date: Fri, 6 Apr 2018 12:56:50 -0400
Subject: [PATCH 4/4] CodeAi generated fix for CWE 401 Memory Leak

Prevent potential leak of memory pointed to by 'dent'

Signed-off-by: C0deAi <techsupport at mycode.ai>
---
 src/lxc/tools/tool_utils.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/lxc/tools/tool_utils.c b/src/lxc/tools/tool_utils.c
index ca325456a..630a627f7 100644
--- a/src/lxc/tools/tool_utils.c
+++ b/src/lxc/tools/tool_utils.c
@@ -795,7 +795,13 @@ int lxc_config_define_add(struct lxc_list *defines, char *arg)
 
 	dent->elem = parse_line(arg);
 	if (!dent->elem)
+	  {
+	    if (dent != NULL) {
+	      free(dent);
+	      dent = NULL;
+	    }
 		return -1;
+	  }
 	lxc_list_add_tail(defines, dent);
 	return 0;
 }


More information about the lxc-devel mailing list