summaryrefslogtreecommitdiff
path: root/lib/vasnprintf.c
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2023-03-31 13:42:49 +0200
committerBruno Haible <bruno@clisp.org>2023-03-31 13:46:18 +0200
commit44c829ff60f5e56834e5b1650fd27b262f142727 (patch)
treed76e4d302dabb0f3e37026cb95d830accebf182c /lib/vasnprintf.c
parenta206ccf8db394a262efc175f1962ba3ea64c8b90 (diff)
downloadgnulib-44c829ff60f5e56834e5b1650fd27b262f142727.tar.gz
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.
Diffstat (limited to 'lib/vasnprintf.c')
-rw-r--r--lib/vasnprintf.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index 83128fd1ea..8ffab85995 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -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;