vasnprintf: Fix crash in %ls directive.
authorBruno Haible <bruno@clisp.org>
Sat, 10 Apr 2010 20:17:02 +0000 (22:17 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 10 Apr 2010 20:17:02 +0000 (22:17 +0200)
ChangeLog
lib/vasnprintf.c

index de6afa42814e0ac688b1f87f2104c1eec0c4b09e..7b6570d42b0a982242042f72a01d333c82efc039 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+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.
index 794fb85f8169c03c06920f53ca374a4fea12c619..f0144a2b12e98d1fc97d86c928de4d232c7b29bc 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;