]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
conf: fix run_script_argv()
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 16 Feb 2018 21:04:35 +0000 (22:04 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 16 Feb 2018 21:04:35 +0000 (22:04 +0100)
Make sure that we allocate the buffer **after** we determined how much space we
need in total.
This fixes a SIGBUS/SIGSEGV Stéphane reported on aarch64 and armf.

Reported-by: Stéphane Graber <stgraber@ubuntu.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/conf.c

index f75d69656577e947f5b289599831d5a85ba03c11..c208d56808ad55653221482ba7a952f2a6bebdbc 100644 (file)
@@ -376,8 +376,6 @@ int run_script_argv(const char *name, unsigned int hook_version,
        if (size > INT_MAX)
                return -EFBIG;
 
-       buffer = alloca(size);
-
        if (hook_version == 0) {
                size += strlen(hookname);
                size++;
@@ -390,19 +388,19 @@ int run_script_argv(const char *name, unsigned int hook_version,
 
                if (size > INT_MAX)
                        return -EFBIG;
+       }
 
+       buffer = alloca(size);
+       if (hook_version == 0)
                buf_pos = snprintf(buffer, size, "exec %s %s %s %s", script, name, section, hookname);
-               if (buf_pos < 0 || (size_t)buf_pos >= size) {
-                       ERROR("Failed to create command line for script \"%s\"", script);
-                       return -1;
-               }
-       } else {
+       else
                buf_pos = snprintf(buffer, size, "exec %s", script);
-               if (buf_pos < 0 || (size_t)buf_pos >= size) {
-                       ERROR("Failed to create command line for script \"%s\"", script);
-                       return -1;
-               }
+       if (buf_pos < 0 || (size_t)buf_pos >= size) {
+               ERROR("Failed to create command line for script \"%s\"", script);
+               return -1;
+       }
 
+       if (hook_version == 1) {
                ret = setenv("LXC_HOOK_TYPE", hookname, 1);
                if (ret < 0) {
                        SYSERROR("Failed to set environment variable: "