changeset 13198:2f3ddf3c58a5

vasnprintf: Fix crash in %ls directive.
author Bruno Haible <bruno@clisp.org>
date Sat, 10 Apr 2010 22:17:02 +0200
parents 5faa02e0b292
children af2bd6fe2a98
files ChangeLog lib/vasnprintf.c
diffstat 2 files changed, 17 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat Apr 10 21:40:23 2010 +0200
+++ b/ChangeLog	Sat Apr 10 22:17:02 2010 +0200
@@ -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.
--- a/lib/vasnprintf.c	Sat Apr 10 21:40:23 2010 +0200
+++ b/lib/vasnprintf.c	Sat Apr 10 22:17:02 2010 +0200
@@ -2605,8 +2605,16 @@
                           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;