vasnprintf: Fix crash in %ls directive.
authorBruno Haible <bruno@clisp.org>
Sat, 10 Apr 2010 20:17:02 +0000 (22:17 +0200)
committerIan Beckwith <ianb@erislabs.net>
Mon, 19 Apr 2010 15:29:27 +0000 (16:29 +0100)
(cherry picked from commit 32d1664e8e930d8fa6a29db4caac4d21623e42c8)

ChangeLog
lib/vasnprintf.c

index debd789..adb84c4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2010-04-10  Bruno Haible  <bruno@clisp.org>
 
+       vasnprintf: Fix crash in %ls directive.
+       * lib/vasnprintf.c (VASNPRINTF): Don't abort when a unconvertible wide
+       string is passed as argument to %ls, with no precision and no width.
+       Reported by Jarno Rajahalme <jarno.rajahalme@nsn.com>.
+
+2010-04-10  Bruno Haible  <bruno@clisp.org>
+
        vasnprintf: Fix multiple test failures on mingw.
        * lib/vasnprintf.c (SNPRINTF) [mingw]: Define to snprintf, not
        _snprintf, or snwprintf, not _snwprintf.
index 794fb85..f0144a2 100644 (file)
@@ -2605,8 +2605,16 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                           count = wctomb (cbuf, *arg);
 #   endif
                           if (count <= 0)
-                            /* Inconsistency.  */
-                            abort ();
+                            {
+                              /* Cannot convert.  */
+                              if (!(result == resultbuf || result == NULL))
+                                free (result);
+                              if (buf_malloced != NULL)
+                                free (buf_malloced);
+                              CLEANUP ();
+                              errno = EILSEQ;
+                              return NULL;
+                            }
                           ENSURE_ALLOCATION (xsum (length, count));
                           memcpy (result + length, cbuf, count);
                           length += count;