]> git.proxmox.com Git - mirror_lxc.git/commitdiff
lxcmntent: remove stack allocations
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 5 Feb 2019 06:00:58 +0000 (07:00 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Wed, 6 Feb 2019 10:47:56 +0000 (11:47 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/include/lxcmntent.c

index 10c10c5496d0e7b0fb7d3e30913c977e02cf0dbb..3d527a9638d868466e35500e040c789b92c8c0df 100644 (file)
@@ -21,7 +21,7 @@
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE 1
 #endif
-#include <alloca.h>
+#include <errno.h>
 #include <mntent.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -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'. */