]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
2005-01-05 Ulrich Drepper <drepper@redhat.com>
authorRoland McGrath <roland@gnu.org>
Wed, 16 Feb 2005 09:45:11 +0000 (09:45 +0000)
committerRoland McGrath <roland@gnu.org>
Wed, 16 Feb 2005 09:45:11 +0000 (09:45 +0000)
[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.

libio/fmemopen.c
stdio-common/Makefile

index ab6ffdd678548f99ced18a1f961ece6107c594c4..c22cba1ec40aa338cc6d2fa172561649c057c37b 100644 (file)
@@ -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;
 
index 3a66f1d0213ab443f8a7b0bb8c7e8c60b734d3c2..947ec8ab31a018e5e378922f4d2aae056834d7bf 100644 (file)
@@ -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