[lxc-devel] [lxc/master] conf: fix suggest_default_idmap()

brauner on Github lxc-bot at linuxcontainers.org
Tue Jan 3 10:09:51 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 493 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170103/92bdf939/attachment.bin>
-------------- next part --------------
From b7930180d1a0fda928ed416b6312c5b59a525567 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 3 Jan 2017 11:08:25 +0100
Subject: [PATCH] conf: fix suggest_default_idmap()

We need to remove the newline otherwise lxc_safe_uint() will fail as it detects
an invalid (non-numeric) char in the string.

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

diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 7d20b55..b346219 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -4514,6 +4514,7 @@ void suggest_default_idmap(void)
 		return;
 	}
 	while (getline(&line, &len, f) != -1) {
+		size_t no_newline = 0;
 		char *p = strchr(line, ':'), *p2;
 		if (*line == '#')
 			continue;
@@ -4530,6 +4531,9 @@ void suggest_default_idmap(void)
 		p2++;
 		if (!*p2)
 			continue;
+		no_newline = strcspn(p2, "\n");
+		p2[no_newline] = '\0';
+
 		if (lxc_safe_uint(p, &uid) < 0)
 			WARN("Could not parse UID.");
 		if (lxc_safe_uint(p2, &urange) < 0)
@@ -4545,6 +4549,7 @@ void suggest_default_idmap(void)
 		return;
 	}
 	while (getline(&line, &len, f) != -1) {
+		size_t no_newline = 0;
 		char *p = strchr(line, ':'), *p2;
 		if (*line == '#')
 			continue;
@@ -4561,6 +4566,9 @@ void suggest_default_idmap(void)
 		p2++;
 		if (!*p2)
 			continue;
+		no_newline = strcspn(p2, "\n");
+		p2[no_newline] = '\0';
+
 		if (lxc_safe_uint(p, &gid) < 0)
 			WARN("Could not parse GID.");
 		if (lxc_safe_uint(p2, &grange) < 0)


More information about the lxc-devel mailing list