]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
conf: less error prone pointer access 1276/head
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 23 Dec 2016 12:10:01 +0000 (13:10 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 11 Apr 2017 12:01:11 +0000 (14:01 +0200)
These functions define pointer to their key shifted by a
number and guard access to it later via another variable.
Let's make this more explicit (and additionally have the
pointer be NULL in the case where it is not supposed to be
used).

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/lxc/conf.c

index c8c2a5452fc93a006ebada993220016194db302d..530a57ed15859970f89627580029a0e9008dca34 100644 (file)
@@ -4256,10 +4256,14 @@ int lxc_clear_cgroups(struct lxc_conf *c, const char *key)
 {
        struct lxc_list *it,*next;
        bool all = false;
-       const char *k = key + 11;
+       const char *k = NULL;
 
        if (strcmp(key, "lxc.cgroup") == 0)
                all = true;
+       else if (strncmp(key, "lxc.cgroup.", sizeof("lxc.cgroup.")-1) == 0)
+               k = key + sizeof("lxc.cgroup.")-1;
+       else
+               return -1;
 
        lxc_list_for_each_safe(it, &c->cgroup, next) {
                struct lxc_cgroup *cg = it->elem;
@@ -4346,11 +4350,15 @@ int lxc_clear_hooks(struct lxc_conf *c, const char *key)
 {
        struct lxc_list *it,*next;
        bool all = false, done = false;
-       const char *k = key + 9;
+       const char *k = NULL;
        int i;
 
        if (strcmp(key, "lxc.hook") == 0)
                all = true;
+       else if (strncmp(key, "lxc.hook.", sizeof("lxc.hook.")-1) == 0)
+               k = key + sizeof("lxc.hook.")-1;
+       else
+               return -1;
 
        for (i=0; i<NUM_LXC_HOOKS; i++) {
                if (all || strcmp(k, lxchook_names[i]) == 0) {