]> 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)
committerChristian Brauner <christian.brauner@canonical.com>
Tue, 22 Nov 2016 03:39:25 +0000 (04:39 +0100)
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
src/lxc/conf.h
src/lxc/confile.c

index 6f40259eb9eff69d5ddf03634374eb8d2a48aba1..6532d8e271d9cafa22522b9b2fcad9fcc3224c0e 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 a9f8a74a1196962005335a6b6280b9d9f1454d63..331a36dd9d5973ca7b08d62690bc204b12bddb35 100644 (file)
@@ -1293,9 +1293,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;
 }
@@ -1327,10 +1331,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;