[lxc-devel] [lxc/master] cgfsng: make trim() safer

brauner on Github lxc-bot at linuxcontainers.org
Thu Mar 2 23:34:17 UTC 2017


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/20170302/3ce303b6/attachment.bin>
-------------- next part --------------
From 2c28d76baa6dc12ed74faea3d040d3ecff799f4f Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Fri, 3 Mar 2017 00:33:40 +0100
Subject: [PATCH] cgfsng: make trim() safer

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 2b772e2..5ad874e 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -986,7 +986,7 @@ static void get_existing_subsystems(char ***klist, char ***nlist)
 static void trim(char *s)
 {
 	size_t len = strlen(s);
-	while (s[len-1] == '\n')
+	while ((len > 1) && (s[len - 1] == '\n'))
 		s[--len] = '\0';
 }
 


More information about the lxc-devel mailing list