From: Christian Brauner Date: Tue, 5 Feb 2019 06:00:58 +0000 (+0100) Subject: lxcmntent: remove stack allocations X-Git-Tag: lxc-3.2.0~164^2~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=57668944d45c99f0034be546953180a485f89403;p=thirdparty%2Flxc.git lxcmntent: remove stack allocations Signed-off-by: Christian Brauner --- diff --git a/src/include/lxcmntent.c b/src/include/lxcmntent.c index 10c10c549..3d527a963 100644 --- a/src/include/lxcmntent.c +++ b/src/include/lxcmntent.c @@ -21,7 +21,7 @@ #ifndef _GNU_SOURCE #define _GNU_SOURCE 1 #endif -#include +#include #include #include #include @@ -160,14 +160,17 @@ FILE *setmntent(const char *file, const char *mode) * I/O functions and "e" to set FD_CLOEXEC. */ size_t modelen = strlen(mode); - char *newmode; + char newmode[256]; - newmode = alloca(modelen + 3); + if (modelen >= (sizeof(newmode) - 3)) { + errno = -EFBIG; + return NULL; + } memcpy(newmode, mode, modelen); memcpy(newmode + modelen, "ce", 3); - return fopen (file, newmode); + return fopen(file, newmode); } /* Close a stream opened with `setmntent'. */