]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
conf/ile: avoid atoi in config_lsm_aa_incomplete()
authorChristian Brauner <christian.brauner@canonical.com>
Fri, 28 Oct 2016 18:10:25 +0000 (20:10 +0200)
committerStéphane Graber <stgraber@ubuntu.com>
Tue, 22 Nov 2016 04:57:32 +0000 (23:57 -0500)
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
src/lxc/conf.h
src/lxc/confile.c

index 70eec92bda12859ab25b7ef62d84573339f84530..d6556b1634e53a9b8ab733187bc54452fc3dfae1 100644 (file)
@@ -317,7 +317,7 @@ struct lxc_conf {
        struct lxc_list hooks[NUM_LXC_HOOKS];
 
        char *lsm_aa_profile;
-       int lsm_aa_allow_incomplete;
+       unsigned int lsm_aa_allow_incomplete;
        char *lsm_se_context;
        int tmp_umount_proc;
        char *seccomp;  // filename with the seccomp rules
index 254c7d9f29d44888c1c4936e4c37242d4710e5b7..8d426cee304a9feb82d85f3c376b9f1e825856c5 100644 (file)
@@ -1288,9 +1288,13 @@ 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)
 {
-       int v = atoi(value);
+       if (lxc_safe_uint(value, &lxc_conf->lsm_aa_allow_incomplete) < 0)
+               return -1;
 
-       lxc_conf->lsm_aa_allow_incomplete = v == 1 ? 1 : 0;
+       if (lxc_conf->lsm_aa_allow_incomplete > 1) {
+               ERROR("Wrong value for lxc.lsm_aa_allow_incomplete. Can only be set to 0 or 1");
+               return -1;
+       }
 
        return 0;
 }
@@ -1322,10 +1326,12 @@ static int config_loglevel(const char *key, const char *value,
        if (!value || strlen(value) == 0)
                return 0;
 
-       if (value[0] >= '0' && value[0] <= '9')
-               newlevel = atoi(value);
-       else
+       if (value[0] >= '0' && value[0] <= '9') {
+               if (lxc_safe_int(value, &newlevel) < 0)
+                       return -1;
+       } else {
                newlevel = lxc_log_priority_to_int(value);
+       }
        // store these values in the lxc_conf, and then try to set for
        // actual current logging.
        lxc_conf->loglevel = newlevel;