[lxc-devel] [lxc/master] cgroups: fix potential nullderef

brauner on Github lxc-bot at linuxcontainers.org
Sun Apr 14 13:32:27 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 619 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190414/ae886891/attachment.bin>
-------------- next part --------------
From b53a08535a8a7f1c8745466ae572886b3b4f5477 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sun, 14 Apr 2019 15:30:22 +0200
Subject: [PATCH] cgroups: fix potential nullderef

The child_path variable is initialized very late in the function so jumping to
the on_error label would cause a nullderef. With the cleanup macros we can
simplify this function to simply do direct returns and avoid that whole issue.

Closes #2935.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/cgroups/cgfsng.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index e40b8079a1..8c3600bb90 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -522,13 +522,17 @@ static bool copy_parent_file(char *path, char *file)
 	*lastslash = '\0';
 	parent_path = must_make_path(path, file, NULL);
 	len = lxc_read_from_file(parent_path, NULL, 0);
-	if (len <= 0)
-		goto on_error;
+	if (len <= 0) {
+		SYSERROR("Failed to determine buffer size");
+		return false;
+	}
 
 	value = must_realloc(NULL, len + 1);
 	ret = lxc_read_from_file(parent_path, value, len);
-	if (ret != len)
-		goto on_error;
+	if (ret != len) {
+		SYSERROR("Failed to read from parent file \"%s\"", parent_path);
+		return false;
+	}
 
 	*lastslash = oldv;
 	child_path = must_make_path(path, file, NULL);
@@ -536,10 +540,6 @@ static bool copy_parent_file(char *path, char *file)
 	if (ret < 0)
 		SYSERROR("Failed to write \"%s\" to file \"%s\"", value, child_path);
 	return ret >= 0;
-
-on_error:
-	SYSERROR("Failed to read file \"%s\"", child_path);
-	return false;
 }
 
 /* Initialize the cpuset hierarchy in first directory of @gname and set


More information about the lxc-devel mailing list