about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndreas Schwab <schwab@redhat.com>2011-03-04 00:48:00 -0500
committerPetr Baudis <pasky@suse.cz>2011-05-27 00:10:58 +0200
commita02af4f1aedc6e1db180b9568d85e6d40d8fb1f6 (patch)
tree71f6af7eea3d24d2cb7f799831d38c3f2e4421e7
parent522cb50e61c109d41df4dbc366312a133e248dca (diff)
downloadglibc-a02af4f1aedc6e1db180b9568d85e6d40d8fb1f6.tar.gz
glibc-a02af4f1aedc6e1db180b9568d85e6d40d8fb1f6.tar.xz
glibc-a02af4f1aedc6e1db180b9568d85e6d40d8fb1f6.zip
Don't read past end of buffer in fmemopen
(cherry picked from commit 9d25c392ba73065ac20f518d1cef1cdc96860545)
-rw-r--r--ChangeLog4
-rw-r--r--libio/fmemopen.c4
2 files changed, 6 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 0aaabe754c..a6fa7a9f96 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2011-03-03  Andreas Schwab  <schwab@redhat.com>
+
+	* libio/fmemopen.c (fmemopen): Don't read past end of buffer.
+
 2011-02-23  Andreas Schwab  <schwab@redhat.com>
 	    Ulrich Drepper  <drepper@gmail.com>
 
diff --git a/libio/fmemopen.c b/libio/fmemopen.c
index d3750fc7de..1a631d5122 100644
--- a/libio/fmemopen.c
+++ b/libio/fmemopen.c
@@ -1,5 +1,5 @@
 /* Fmemopen implementation.
-   Copyright (C) 2000, 2002, 2005, 2006, 2008, 2009
+   Copyright (C) 2000, 2002, 2005, 2006, 2008, 2009, 2011
    Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Hanno Mueller, kontakt@hanno.de, 2000.
@@ -243,7 +243,7 @@ fmemopen (void *buf, size_t len, const char *mode)
   if (mode[0] == 'w')
     c->buffer[0] = '\0';
 
-  c->maxpos = strlen (c->buffer);
+  c->maxpos = strnlen (c->buffer, len);
 
   if (mode[0] == 'a')
     c->pos = c->maxpos;