diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2016-09-14 12:38:58 +0200 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2016-09-14 12:40:09 +0200 |
commit | 6a2b1e8bc87aca9f100a08c15335246a1744b1fd (patch) | |
tree | 2958e85373b0c41951bd5bc92322b84d742cba37 /main/musl/0001-use-dynamic-buffer-for-getmntent.patch | |
parent | a5f4ba336e4638637bdbf06c5c64fb7c936adc58 (diff) | |
download | aports-6a2b1e8bc87aca9f100a08c15335246a1744b1fd.tar.bz2 aports-6a2b1e8bc87aca9f100a08c15335246a1744b1fd.tar.xz |
main/musl: fix for getmntent
ref #5703
Diffstat (limited to 'main/musl/0001-use-dynamic-buffer-for-getmntent.patch')
-rw-r--r-- | main/musl/0001-use-dynamic-buffer-for-getmntent.patch | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/main/musl/0001-use-dynamic-buffer-for-getmntent.patch b/main/musl/0001-use-dynamic-buffer-for-getmntent.patch new file mode 100644 index 0000000000..12feaa8266 --- /dev/null +++ b/main/musl/0001-use-dynamic-buffer-for-getmntent.patch @@ -0,0 +1,66 @@ +From c0dd2db34a8a5d51699406a90a4f87cb3129d5a1 Mon Sep 17 00:00:00 2001 +From: Natanael Copa <ncopa@alpinelinux.org> +Date: Thu, 8 Sep 2016 09:06:22 +0200 +Subject: [PATCH] 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> +--- + src/misc/mntent.c | 16 ++++++++++++---- + 1 file changed, 12 insertions(+), 4 deletions(-) + +diff --git a/src/misc/mntent.c b/src/misc/mntent.c +index a16d652..722a030 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 = NULL; ++static size_t internal_bufsize = 0; ++ ++#define SENTINEL (char *)&internal_buf ++ + FILE *setmntent(const char *name, const char *mode) + { + return fopen(name, mode); +@@ -16,13 +21,17 @@ 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 +58,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) +-- +2.10.0 + |