Commit f53c6ce7 by Christian Brauner Committed by Stéphane Graber

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: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 569c5fe1
...@@ -4513,6 +4513,7 @@ void suggest_default_idmap(void) ...@@ -4513,6 +4513,7 @@ void suggest_default_idmap(void)
return; return;
} }
while (getline(&line, &len, f) != -1) { while (getline(&line, &len, f) != -1) {
size_t no_newline = 0;
char *p = strchr(line, ':'), *p2; char *p = strchr(line, ':'), *p2;
if (*line == '#') if (*line == '#')
continue; continue;
...@@ -4529,6 +4530,9 @@ void suggest_default_idmap(void) ...@@ -4529,6 +4530,9 @@ void suggest_default_idmap(void)
p2++; p2++;
if (!*p2) if (!*p2)
continue; continue;
no_newline = strcspn(p2, "\n");
p2[no_newline] = '\0';
if (lxc_safe_uint(p, &uid) < 0) if (lxc_safe_uint(p, &uid) < 0)
WARN("Could not parse UID."); WARN("Could not parse UID.");
if (lxc_safe_uint(p2, &urange) < 0) if (lxc_safe_uint(p2, &urange) < 0)
...@@ -4544,6 +4548,7 @@ void suggest_default_idmap(void) ...@@ -4544,6 +4548,7 @@ void suggest_default_idmap(void)
return; return;
} }
while (getline(&line, &len, f) != -1) { while (getline(&line, &len, f) != -1) {
size_t no_newline = 0;
char *p = strchr(line, ':'), *p2; char *p = strchr(line, ':'), *p2;
if (*line == '#') if (*line == '#')
continue; continue;
...@@ -4560,6 +4565,9 @@ void suggest_default_idmap(void) ...@@ -4560,6 +4565,9 @@ void suggest_default_idmap(void)
p2++; p2++;
if (!*p2) if (!*p2)
continue; continue;
no_newline = strcspn(p2, "\n");
p2[no_newline] = '\0';
if (lxc_safe_uint(p, &gid) < 0) if (lxc_safe_uint(p, &gid) < 0)
WARN("Could not parse GID."); WARN("Could not parse GID.");
if (lxc_safe_uint(p2, &grange) < 0) if (lxc_safe_uint(p2, &grange) < 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment