summaryrefslogtreecommitdiff
path: root/src/misc
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2016-09-08 19:07:31 +0200
committerRich Felker <dalias@aerifal.cx>2016-10-20 01:20:27 -0400
commit05973dc3bbc1aca9b3c8347de6879ed72147ab3b (patch)
treecb2504eebdf2f05acf895cca5cb7076b39da02de /src/misc
parent167dfe9672c116b315e72e57a55c7769f180dffa (diff)
downloadmusl-05973dc3bbc1aca9b3c8347de6879ed72147ab3b.tar.gz
musl-05973dc3bbc1aca9b3c8347de6879ed72147ab3b.tar.bz2
musl-05973dc3bbc1aca9b3c8347de6879ed72147ab3b.tar.xz
musl-05973dc3bbc1aca9b3c8347de6879ed72147ab3b.zip
use dynamic buffer for getmntent
overlayfs may have fairly long lines so we use getline to allocate a buffer dynamically. The buffer will be allocated on first use, expand as needed, but will never be free'ed. Downstream bug: http://bugs.alpinelinux.org/issues/5703 Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Diffstat (limited to 'src/misc')
-rw-r--r--src/misc/mntent.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/misc/mntent.c b/src/misc/mntent.c
index a16d6525..eabb8200 100644
--- a/src/misc/mntent.c
+++ b/src/misc/mntent.c
@@ -3,6 +3,11 @@
#include <mntent.h>
#include <errno.h>
+static char *internal_buf;
+static size_t internal_bufsize;
+
+#define SENTINEL (char *)&internal_buf
+
FILE *setmntent(const char *name, const char *mode)
{
return fopen(name, mode);
@@ -16,13 +21,18 @@ int endmntent(FILE *f)
struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *linebuf, int buflen)
{
- int cnt, n[8];
+ int cnt, n[8], use_internal = (linebuf == SENTINEL);
mnt->mnt_freq = 0;
mnt->mnt_passno = 0;
do {
- fgets(linebuf, buflen, f);
+ if (use_internal) {
+ getline(&internal_buf, &internal_bufsize, f);
+ linebuf = internal_buf;
+ } else {
+ fgets(linebuf, buflen, f);
+ }
if (feof(f) || ferror(f)) return 0;
if (!strchr(linebuf, '\n')) {
fscanf(f, "%*[^\n]%*[\n]");
@@ -49,9 +59,8 @@ struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *linebuf, int bufle
struct mntent *getmntent(FILE *f)
{
- static char linebuf[256];
static struct mntent mnt;
- return getmntent_r(f, &mnt, linebuf, sizeof linebuf);
+ return getmntent_r(f, &mnt, SENTINEL, 0);
}
int addmntent(FILE *f, const struct mntent *mnt)