The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/1596

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
We recently fixed a bug whereby lots of config items could be set but couldn't
be unset via clear_config_item(). This was especially problematic when copying
containers because the config items where stacked onto each other if they were
changed. The same problem for api calls to clear_config_item() +
set_config_item(). The fix however did not take into account that this means
that whitespace character for all of these config items need to be accounted
for. This commit does.

Closes #1595.

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
From 8738738dc883175d070e1ef99ebd02dca8a4de66 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@ubuntu.com>
Date: Mon, 29 May 2017 11:50:27 +0200
Subject: [PATCH] confile: fix parsing

We recently fixed a bug whereby lots of config items could be set but couldn't
be unset via clear_config_item(). This was especially problematic when copying
containers because the config items where stacked onto each other if they were
changed. The same problem for api calls to clear_config_item() +
set_config_item(). The fix however did not take into account that this means
that whitespace character for all of these config items need to be accounted
for. This commit does.

Closes #1595.

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
---
 src/lxc/confile.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/lxc/utils.h   |  1 +
 2 files changed, 64 insertions(+), 1 deletion(-)

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 4114e9fff..a82790260 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -1151,6 +1151,11 @@ static int config_init_uid(const char *key, const char 
*value,
                                 struct lxc_conf *lxc_conf)
 {
        unsigned int init_uid;
+       size_t empty;
+
+       empty = strspn(value, LXC_WHITESPACE);
+       if (*(value + empty) == '\0')
+               return 0;
 
        if (lxc_safe_uint(value, &init_uid) < 0)
                return -1;
@@ -1163,6 +1168,11 @@ static int config_init_gid(const char *key, const char 
*value,
                                 struct lxc_conf *lxc_conf)
 {
        unsigned int init_gid;
+       size_t empty;
+
+       empty = strspn(value, LXC_WHITESPACE);
+       if (*(value + empty) == '\0')
+               return 0;
 
        if (lxc_safe_uint(value, &init_gid) < 0)
                return -1;
@@ -1227,6 +1237,12 @@ static int config_personality(const char *key, const 
char *value,
 static int config_pts(const char *key, const char *value,
                      struct lxc_conf *lxc_conf)
 {
+       size_t empty;
+
+       empty = strspn(value, LXC_WHITESPACE);
+       if (*(value + empty) == '\0')
+               return 0;
+
        if (lxc_safe_uint(value, &lxc_conf->pts) < 0)
                return -1;
 
@@ -1236,6 +1252,11 @@ static int config_pts(const char *key, const char *value,
 static int config_start(const char *key, const char *value,
                      struct lxc_conf *lxc_conf)
 {
+       size_t empty;
+       empty = strspn(value, LXC_WHITESPACE);
+       if (*(value + empty) == '\0')
+               return 0;
+
        if(strcmp(key, "lxc.start.auto") == 0) {
                if (lxc_safe_uint(value, &lxc_conf->start_auto) < 0)
                        return -1;
@@ -1260,6 +1281,12 @@ static int config_start(const char *key, const char 
*value,
 static int config_monitor(const char *key, const char *value,
                          struct lxc_conf *lxc_conf)
 {
+       size_t empty;
+
+       empty = strspn(value, LXC_WHITESPACE);
+       if (*(value + empty) == '\0')
+               return 0;
+
        if(strcmp(key, "lxc.monitor.unshare") == 0) {
                if (lxc_safe_uint(value, &lxc_conf->monitor_unshare) < 0)
                        return -1;
@@ -1345,6 +1372,11 @@ static int config_environment(const char *key, const 
char *value,
 static int config_tty(const char *key, const char *value,
                      struct lxc_conf *lxc_conf)
 {
+       size_t empty;
+       empty = strspn(value, LXC_WHITESPACE);
+       if (*(value + empty) == '\0')
+               return 0;
+
        if (lxc_safe_uint(value, &lxc_conf->tty) < 0)
                return -1;
 
@@ -1360,6 +1392,12 @@ static int config_ttydir(const char *key, const char 
*value,
 static int config_kmsg(const char *key, const char *value,
                          struct lxc_conf *lxc_conf)
 {
+       size_t empty;
+
+       empty = strspn(value, LXC_WHITESPACE);
+       if (*(value + empty) == '\0')
+               return 0;
+
        if (lxc_safe_uint(value, &lxc_conf->kmsg) < 0)
                return -1;
 
@@ -1378,6 +1416,12 @@ static int config_lsm_aa_profile(const char *key, const 
char *value,
 static int config_lsm_aa_incomplete(const char *key, const char *value,
                                 struct lxc_conf *lxc_conf)
 {
+       size_t empty;
+
+       empty = strspn(value, LXC_WHITESPACE);
+       if (*(value + empty) == '\0')
+               return 0;
+
        if (lxc_safe_uint(value, &lxc_conf->lsm_aa_allow_incomplete) < 0)
                return -1;
 
@@ -1412,8 +1456,10 @@ static int config_loglevel(const char *key, const char 
*value,
                             struct lxc_conf *lxc_conf)
 {
        int newlevel;
+       size_t empty;
 
-       if (!value || strlen(value) == 0)
+       empty = strspn(value, LXC_WHITESPACE);
+       if (*(value + empty) == '\0')
                return 0;
 
        if (value[0] >= '0' && value[0] <= '9') {
@@ -1431,6 +1477,11 @@ static int config_loglevel(const char *key, const char 
*value,
 static int config_autodev(const char *key, const char *value,
                          struct lxc_conf *lxc_conf)
 {
+       size_t empty;
+       empty = strspn(value, LXC_WHITESPACE);
+       if (*(value + empty) == '\0')
+               return 0;
+
        if (lxc_safe_uint(value, &lxc_conf->autodev) < 0)
                return -1;
 
@@ -3220,6 +3271,12 @@ bool network_new_hwaddrs(struct lxc_conf *conf)
 static int config_ephemeral(const char *key, const char *value,
                            struct lxc_conf *lxc_conf)
 {
+       size_t empty;
+
+       empty = strspn(value, LXC_WHITESPACE);
+       if (*(value + empty) == '\0')
+               return 0;
+
        if (lxc_safe_uint(value, &lxc_conf->ephemeral) < 0)
                return -1;
 
@@ -3249,6 +3306,11 @@ static int config_no_new_privs(const char *key, const 
char *value,
                                    struct lxc_conf *lxc_conf)
 {
        unsigned int v;
+       size_t empty;
+
+       empty = strspn(value, LXC_WHITESPACE);
+       if (*(value + empty) == '\0')
+               return 0;
 
        if (lxc_safe_uint(value, &v) < 0)
                return -1;
diff --git a/src/lxc/utils.h b/src/lxc/utils.h
index 320aa6bf7..b204ca383 100644
--- a/src/lxc/utils.h
+++ b/src/lxc/utils.h
@@ -44,6 +44,7 @@
 #define LXC_NUMSTRLEN64 21
 #define LXC_LINELEN 4096
 #define LXC_IDMAPLEN 4096
+#define LXC_WHITESPACE " \t\n\r"
 
 /* returns 1 on success, 0 if there were any failures */
 extern int lxc_rmdir_onedev(char *path, const char *exclude);
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to