]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
backport fix buffer overflow for writes to memory buffer stream (PR18549)
authorStan Shebs <stanshebs@google.com>
Tue, 7 Jul 2015 03:51:10 +0000 (20:51 -0700)
committerStan Shebs <stanshebs@google.com>
Tue, 7 Jul 2015 03:51:10 +0000 (20:51 -0700)
README.google
libio/fmemopen.c
libio/test-fmemopen.c

index 9937af55923b580227fd2e743bb0ac5d1d698a34..2c776b0a06468f84c041329c7b04f31ba171e10f 100644 (file)
@@ -438,3 +438,8 @@ elf/dl-load.c
   For b/8315591, b/20141439 correct off-by-one error that resulted in last
   byte of l_name being random garbage.
   (ppluzhnikov, google-local)
+
+libio/fmemopen.c
+libio/test-fmemopen.c
+  For b/22167761, backport fix buffer overflow for writes to memory buffer stream (PR18549)
+  https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=7c2ce714d4e853aadbec13b920576fdfada520f1
index e370a8b9e7ea0e1e09bb98ce0da4685540d1f29a..66aa5aebeb8de04102c8d735e07657aef04f471c 100644 (file)
@@ -124,7 +124,7 @@ fmemopen_write (void *cookie, const char *b, size_t s)
 
   if (c->pos + s + addnullc > c->size)
     {
-      if ((size_t) (c->pos + addnullc) == c->size)
+      if ((size_t) (c->pos + addnullc) >= c->size)
        {
          __set_errno (ENOSPC);
          return 0;
index 30998940e16d795b01d050dfab5eb6cfe8f023b3..63ca89f300091b92448587eddcb89b04d86a0e03 100644 (file)
@@ -1,5 +1,5 @@
 /* Test for fmemopen implementation.
-   Copyright (C) 2000-2014 Free Software Foundation, Inc.
+   Copyright (C) 2000-2015 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Hanno Mueller, kontakt@hanno.de, 2000.
 
@@ -21,19 +21,31 @@ static char buffer[] = "foobar";
 
 #include <stdio.h>
 #include <string.h>
+#include <errno.h>
 
-int
-main (void)
+static int
+do_test (void)
 {
   int ch;
   FILE *stream;
+  int ret = 0;
 
-  stream = fmemopen (buffer, strlen (buffer), "r");
+  stream = fmemopen (buffer, strlen (buffer), "r+");
 
   while ((ch = fgetc (stream)) != EOF)
     printf ("Got %c\n", ch);
 
+  fputc ('1', stream);
+  if (fflush (stream) != EOF || errno != ENOSPC)
+    {
+      printf ("fflush didn't fail with ENOSPC\n");
+      ret = 1;
+    }
+
   fclose (stream);
 
-  return 0;
+  return ret;
 }
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"