Unverified Commit 3d54b700 by Wolfgang Bumiller Committed by Stéphane Graber

conf: less error prone pointer access

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: 's avatarWolfgang Bumiller <w.bumiller@proxmox.com>
parent 00a67661
...@@ -4582,10 +4582,14 @@ int lxc_clear_cgroups(struct lxc_conf *c, const char *key) ...@@ -4582,10 +4582,14 @@ int lxc_clear_cgroups(struct lxc_conf *c, const char *key)
{ {
struct lxc_list *it,*next; struct lxc_list *it,*next;
bool all = false; bool all = false;
const char *k = key + 11; const char *k = NULL;
if (strcmp(key, "lxc.cgroup") == 0) if (strcmp(key, "lxc.cgroup") == 0)
all = true; 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) { lxc_list_for_each_safe(it, &c->cgroup, next) {
struct lxc_cgroup *cg = it->elem; struct lxc_cgroup *cg = it->elem;
...@@ -4634,11 +4638,15 @@ int lxc_clear_hooks(struct lxc_conf *c, const char *key) ...@@ -4634,11 +4638,15 @@ int lxc_clear_hooks(struct lxc_conf *c, const char *key)
{ {
struct lxc_list *it,*next; struct lxc_list *it,*next;
bool all = false, done = false; bool all = false, done = false;
const char *k = key + 9; const char *k = NULL;
int i; int i;
if (strcmp(key, "lxc.hook") == 0) if (strcmp(key, "lxc.hook") == 0)
all = true; 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++) { for (i=0; i<NUM_LXC_HOOKS; i++) {
if (all || strcmp(k, lxchook_names[i]) == 0) { if (all || strcmp(k, lxchook_names[i]) == 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