diff options
author | Lennart Poettering <lennart@poettering.net> | 2012-05-03 23:23:38 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2012-05-03 23:23:38 +0200 |
commit | 37099707e26ef2c6d215f6e7f17dd46bf6aad586 (patch) | |
tree | 0816bb29e8f11fa328fca87d2ace102f601a5f98 | |
parent | 6e476bc9d18c706564d797882df6a27ab2d45b8b (diff) |
cgroup: fix alloca() misuse in cg_shorten_controllers()
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | src/shared/cgroup-util.c | 33 |
2 files changed, 24 insertions, 11 deletions
@@ -62,4 +62,2 @@ Features: -* cg_shorten_controllers() misuses alloca() - * udev: move to LGPL diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c index d34c14272..1f310d31f 100644 --- a/src/shared/cgroup-util.c +++ b/src/shared/cgroup-util.c @@ -567,5 +567,19 @@ int cg_get_path(const char *controller, const char *path, const char *suffix, ch +static int check(const char *p) { + char *cc; + + assert(p); + + /* Check if this controller actually really exists */ + cc = alloca(sizeof("/sys/fs/cgroup/") + strlen(p)); + strcpy(stpcpy(cc, "/sys/fs/cgroup/"), p); + if (access(cc, F_OK) < 0) + return -errno; + + return 0; +} + int cg_get_path_and_check(const char *controller, const char *path, const char *suffix, char **fs) { const char *p; - char *cc; + int r; @@ -577,2 +591,3 @@ int cg_get_path_and_check(const char *controller, const char *path, const char * + /* Normalize the controller syntax */ p = normalize_controller(controller); @@ -580,6 +595,5 @@ int cg_get_path_and_check(const char *controller, const char *path, const char * /* Check if this controller actually really exists */ - cc = alloca(sizeof("/sys/fs/cgroup/") + strlen(p)); - strcpy(stpcpy(cc, "/sys/fs/cgroup/"), p); - if (access(cc, F_OK) < 0) - return -errno; + r = check(p); + if (r < 0) + return r; @@ -1113,3 +1127,4 @@ char **cg_shorten_controllers(char **controllers) { for (f = controllers, t = controllers; *f; f++) { - char *cc; + int r; + const char *p; @@ -1120,6 +1135,6 @@ char **cg_shorten_controllers(char **controllers) { - cc = alloca(sizeof("/sys/fs/cgroup/") + strlen(*f)); - strcpy(stpcpy(cc, "/sys/fs/cgroup/"), *f); + p = normalize_controller(*f); - if (access(cc, F_OK) < 0) { + r = check(p); + if (r < 0) { log_debug("Controller %s is not available, removing from controllers list.", *f); |