]> Savannah Git Hosting - gnulib.git/commitdiff
vasnwprintf: Fix crash upon conversion failure when processing %s.
authorBruno Haible <bruno@clisp.org>
Fri, 31 Mar 2023 11:42:49 +0000 (13:42 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 31 Mar 2023 11:46:18 +0000 (13:46 +0200)
* lib/vasnprintf.c (VASNPRINTF): When processing %s with !has_precision
and !has_width, don't call abort() if there is a conversion failure.

ChangeLog
lib/vasnprintf.c

index eed2321d8f8236a92b63c3e063ab2d8ee34f9157..b358a707cf6856c1ef01eeeb7a7fd1761b3b34dc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2023-03-31  Bruno Haible  <bruno@clisp.org>
+
+       vasnwprintf: Fix crash upon conversion failure when processing %s.
+       * lib/vasnprintf.c (VASNPRINTF): When processing %s with !has_precision
+       and !has_width, don't call abort() if there is a conversion failure.
+
 2023-03-30  Bruno Haible  <bruno@clisp.org>
 
        Avoid test failures on Android.
index 83128fd1ea397a987649a0d35576635c831dfbb9..8ffab85995e36c8c63def4f672d0bc382c5d4726 100644 (file)
@@ -3099,10 +3099,12 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 #  else
                           count = mbtowc (&wc, arg, arg_end - arg);
 #  endif
-                          if (count <= 0)
-                            /* mbrtowc not consistent with mbrlen, or mbtowc
-                               not consistent with mblen.  */
+                          if (count == 0)
+                            /* mbrtowc not consistent with strlen.  */
                             abort ();
+                          if (count < 0)
+                            /* Invalid or incomplete multibyte character.  */
+                            goto fail_with_EILSEQ;
                           ENSURE_ALLOCATION (xsum (length, 1));
                           result[length++] = wc;
                           arg += count;