diff options
author | Paul Pluzhnikov <ppluzhnikov@google.com> | 2015-02-24 08:05:34 -0800 |
---|---|---|
committer | Paul Pluzhnikov <ppluzhnikov@google.com> | 2015-02-24 08:05:34 -0800 |
commit | 6909d2767580b680138a6aa49aabf4976770e9f6 (patch) | |
tree | 7f2b0beb70e3a2119193bbc12672bf8d19b79869 /libio/tst-fopenloc.c | |
parent | 65f6f938cd562a614a68e15d0581a34b177ec29d (diff) | |
download | glibc-6909d2767580b680138a6aa49aabf4976770e9f6.zip glibc-6909d2767580b680138a6aa49aabf4976770e9f6.tar.gz glibc-6909d2767580b680138a6aa49aabf4976770e9f6.tar.bz2 |
Fix BZ #17916 - fopen unbounded stack usage for ccs= modes
Diffstat (limited to 'libio/tst-fopenloc.c')
-rw-r--r-- | libio/tst-fopenloc.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/libio/tst-fopenloc.c b/libio/tst-fopenloc.c index 1336023..48c2d3b 100644 --- a/libio/tst-fopenloc.c +++ b/libio/tst-fopenloc.c @@ -24,10 +24,36 @@ #include <stdlib.h> #include <string.h> #include <wchar.h> +#include <sys/resource.h> static const char inputfile[] = "../iconvdata/testdata/ISO-8859-1"; +static +int do_bz17916 (void) +{ + /* BZ #17916 -- check invalid large ccs= case. */ + struct rlimit rl; + getrlimit (RLIMIT_STACK, &rl); + rl.rlim_cur = 1024 * 1024; + setrlimit (RLIMIT_STACK, &rl); + + const size_t sz = 2 * 1024 * 1024; + char *ccs = malloc (sz); + strcpy (ccs, "r,ccs="); + memset (ccs + 6, 'A', sz - 6 - 1); + ccs[sz - 1] = '\0'; + + FILE *fp = fopen (inputfile, ccs); + if (fp != NULL) + { + printf ("unxpected success\n"); + return 1; + } + free (ccs); + + return 0; +} static int do_test (void) @@ -57,7 +83,7 @@ do_test (void) fclose (fp); - return 0; + return do_bz17916 (); } #define TEST_FUNCTION do_test () |