From: Christian Brauner Date: Fri, 16 Feb 2018 21:04:35 +0000 (+0100) Subject: conf: fix run_script_argv() X-Git-Tag: lxc-3.0.0.beta1~25^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=327cce76ad2f435e84b7d53e64a1e0a5edbd568b;p=thirdparty%2Flxc.git conf: fix run_script_argv() 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 Signed-off-by: Christian Brauner --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index f75d69656..c208d5680 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -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: "