diff options
author | Adhemerval Zanella <adhemerval.zanella@linaro.com> | 2015-07-15 16:15:47 -0300 |
---|---|---|
committer | Adhemerval Zanella <adhemerval.zanella@linaro.com> | 2015-07-16 15:21:49 -0300 |
commit | 787813b14425c9c2e699a90e27eee1cfdfe73ec2 (patch) | |
tree | 8fb22cea093163f6706988781a5eb6012dd442e1 /libio/fmemopen.c | |
parent | b42f8cad52ebfbfd43ebf6e42e606b489ffbd466 (diff) | |
download | glibc-787813b14425c9c2e699a90e27eee1cfdfe73ec2.tar.gz glibc-787813b14425c9c2e699a90e27eee1cfdfe73ec2.tar.xz glibc-787813b14425c9c2e699a90e27eee1cfdfe73ec2.zip |
libio: Fix fmemopen 'w' mode with provided buffer
If 'w' mode is used with a provided buffer the fmemopen will try to find the first null byte to set as maximum internal stream size. It should be done only for append mode ('a'). Kudos for Stefan Liebler for finding this error on s390-32. * libio/fmemopen.c (__fmemopen): Fix 'w' openmode with provided buffer. * stdio-common/tst-fmemopen2.c (do_test_with_buffer): Fix typo and fail output information.
Diffstat (limited to 'libio/fmemopen.c')
-rw-r--r-- | libio/fmemopen.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/libio/fmemopen.c b/libio/fmemopen.c index e6e6a49f76..3ab3e8dac4 100644 --- a/libio/fmemopen.c +++ b/libio/fmemopen.c @@ -150,7 +150,7 @@ __fmemopen (void *buf, size_t len, const char *mode) cookie_io_functions_t iof; fmemopen_cookie_t *c; - c = (fmemopen_cookie_t *) malloc (sizeof (fmemopen_cookie_t)); + c = (fmemopen_cookie_t *) calloc (sizeof (fmemopen_cookie_t), 1); if (c == NULL) return NULL; @@ -165,7 +165,6 @@ __fmemopen (void *buf, size_t len, const char *mode) return NULL; } c->buffer[0] = '\0'; - c->maxpos = 0; } else { @@ -182,7 +181,8 @@ __fmemopen (void *buf, size_t len, const char *mode) if (mode[0] == 'w' && mode[1] == '+') c->buffer[0] = '\0'; - c->maxpos = strnlen (c->buffer, len); + if (mode[0] == 'a') + c->maxpos = strnlen (c->buffer, len); } |