__xpg_strerror_r should not clobber strerror buffer

Eric Blake eblake@redhat.com
Mon May 23 20:52:00 GMT 2011


On 05/23/2011 02:45 PM, Eric Blake wrote:
> On 05/21/2011 07:35 PM, Christopher Faylor wrote:
>> On Sat, May 21, 2011 at 07:26:37PM -0600, Eric Blake wrote:
>>> POSIX says that no other function in the standard should clobber the
>>> strerror buffer.  Our strerror_r is a GNU extension, so it can get away
>>> with clobbering the buffer (but if we wanted to fix it, we would have to
>>> separate _my_tls.locals.strerror_buf into two different buffers).

Shoot.  This introduced an off-by-one buffer overrun.  I'm pushing this
followup.  Meanwhile, do we want a second buffer, so that the GNU
strerror_r won't clobber the strerror buffer?

+++ b/winsup/cygwin/ChangeLog
@@ -2,6 +2,7 @@

 	* errno.cc (strerror): Print unknown errno as int.
 	(__xpg_strerror_r): Likewise, and don't clobber strerror buffer.
+	* cygtls.h (strerror_buf): Resize to allow '-'.

 2011-05-23  Corinna Vinschen  <corinna@vinschen.de>

diff --git a/winsup/cygwin/cygtls.h b/winsup/cygwin/cygtls.h
index 4d4306b..f911a6c 100644
--- a/winsup/cygwin/cygtls.h
+++ b/winsup/cygwin/cygtls.h
@@ -109,7 +109,7 @@ struct _local_storage
   } select;

   /* strerror */
-  char strerror_buf[sizeof ("Unknown error 4294967295")];
+  char strerror_buf[sizeof ("Unknown error -2147483648")];

   /* times.cc */
   char timezone_buf[20];


-- 
Eric Blake   eblake@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20110523/3e63346c/attachment.sig>


More information about the Cygwin-patches mailing list