[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-gnulib] vasprintf proposed fix for int overflow check

From: Paul Eggert
Subject: [Bug-gnulib] vasprintf proposed fix for int overflow check
Date: 29 Oct 2003 09:49:59 -0800
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

Here's a proposed patch to vasprintf.c.  I'm not sure what to do on
older hosts where EOVERFLOW isn't defined, so I just punted and left
things alone in that case; it probably doesn't matter all that much
these days.

2003-10-29  Paul Eggert  <address@hidden>

        * vasprintf.c: Include <errno.h>, <limits.h>, <stdlib.h>.
        (vasprintf) [defined EOVERFLOW]: If the resulting length
        exceeds INT_MAX, report an EOVERFLOW error.

Index: lib/vasprintf.c
RCS file: /cvsroot/gnulib/gnulib/lib/vasprintf.c,v
retrieving revision 1.2
diff -p -u -r1.2 vasprintf.c
--- lib/vasprintf.c     14 Jul 2003 22:44:04 -0000      1.2
+++ lib/vasprintf.c     29 Oct 2003 17:24:06 -0000
@@ -24,6 +24,10 @@
 #include "vasnprintf.h"
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
 vasprintf (char **resultp, const char *format, va_list args)
@@ -31,6 +35,14 @@ vasprintf (char **resultp, const char *f
   char *result = vasnprintf (NULL, &length, format, args);
   if (result == NULL)
     return -1;
+  if (INT_MAX < length)
+    {
+      free (result);
+      errno = EOVERFLOW;
+      return -1;
+    }
   *resultp = result;
   /* Return the number of resulting bytes, excluding the trailing NUL.  */
   return length;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]