From: Roland McGrath Date: Wed, 16 Feb 2005 09:45:11 +0000 (+0000) Subject: 2005-01-05 Ulrich Drepper X-Git-Tag: cvs/fedora-glibc-2_3-20050216T1256~72 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b25db04c7b8c439edc5fb898356c80645cf17419;p=thirdparty%2Fglibc.git 2005-01-05 Ulrich Drepper [BZ #730] * libio/iofopncook.c (_IO_cookie_seekoff): Define. Mark offset as invalid to disable optimizations in fileops which won't work here. (_IO_cookie_jumps): Use it. (_IO_old_cookie_jumps): Likewise. * libio/fmemopen.c (fmemopen_seek): Result must be returned in *P, not the return value. * stdio-common/Makefile (tests): Add tst-fmemopen2. * stdio-common/tst-fmemopen2.c: New file. --- diff --git a/libio/fmemopen.c b/libio/fmemopen.c index ab6ffdd6785..c22cba1ec40 100644 --- a/libio/fmemopen.c +++ b/libio/fmemopen.c @@ -27,8 +27,6 @@ * but couldn't find it in libio. The following snippet of code is an * attempt to implement what glibc's documentation describes. * - * No, it isn't really tested yet. :-) - * * * * I already see some potential problems: @@ -166,7 +164,7 @@ fmemopen_seek (void *cookie, _IO_off64_t *p, int w) break; case SEEK_END: - np = c->size - *p; + np = c->maxpos - *p; break; default: @@ -176,9 +174,9 @@ fmemopen_seek (void *cookie, _IO_off64_t *p, int w) if (np < 0 || (size_t) np > c->size) return -1; - c->pos = np; + *p = c->pos = np; - return np; + return 0; } @@ -203,6 +201,13 @@ fmemopen (void *buf, size_t len, const char *mode) cookie_io_functions_t iof; fmemopen_cookie_t *c; + if (len == 0) + { + einval: + __set_errno (EINVAL); + return NULL; + } + c = (fmemopen_cookie_t *) malloc (sizeof (fmemopen_cookie_t)); if (c == NULL) return NULL; @@ -220,7 +225,12 @@ fmemopen (void *buf, size_t len, const char *mode) c->buffer[0] = '\0'; } else - c->buffer = buf; + { + if ((uintptr_t) len > -(uintptr_t) buf) + goto einval; + + c->buffer = buf; + } c->size = len; diff --git a/stdio-common/Makefile b/stdio-common/Makefile index 3a66f1d0213..947ec8ab31a 100644 --- a/stdio-common/Makefile +++ b/stdio-common/Makefile @@ -53,7 +53,7 @@ tests := tstscanf test_rdwr test-popen tstgetln test-fseek \ scanf11 scanf12 tst-tmpnam tst-cookie tst-obprintf tst-sscanf \ tst-swprintf tst-fseek tst-fmemopen test-vfprintf tst-gets \ tst-perror tst-sprintf tst-rndseek tst-fdopen tst-fphex bug14 bug15 \ - tst-popen tst-unlockedio + tst-popen tst-unlockedio tst-fmemopen2 test-srcs = tst-unbputc tst-printf