lxcmntent: remove stack allocations

parent 89876c4f
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
#define _GNU_SOURCE 1 #define _GNU_SOURCE 1
#endif #endif
#include <alloca.h> #include <errno.h>
#include <mntent.h> #include <mntent.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -160,14 +160,17 @@ FILE *setmntent(const char *file, const char *mode) ...@@ -160,14 +160,17 @@ FILE *setmntent(const char *file, const char *mode)
* I/O functions and "e" to set FD_CLOEXEC. * I/O functions and "e" to set FD_CLOEXEC.
*/ */
size_t modelen = strlen(mode); 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, mode, modelen);
memcpy(newmode + modelen, "ce", 3); memcpy(newmode + modelen, "ce", 3);
return fopen (file, newmode); return fopen(file, newmode);
} }
/* Close a stream opened with `setmntent'. */ /* Close a stream opened with `setmntent'. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment