Cygwin: mbrtowi: fix segfault when pwi is NULL

mbrtowi was missing null-checks on pwi, but NULL is passed from
regex/engine.c:173.

In a git repo with sendemail.smtpserver set, this results in a segfault when
using git-send-email, which calls:

git config --get-regexp '^sende?mail[.]'

Fixes: 60c25da90d ("Cygwin: mbrtowi: define replacement for mbrtowc, returning UTF-32 value")
Signed-off-by: David McFarland <corngood@gmail.com>
This commit is contained in:
David McFarland 2023-04-18 17:05:34 -03:00 committed by Corinna Vinschen
parent c743751aaf
commit 53f7fb20a0
1 changed files with 4 additions and 2 deletions

View File

@ -159,7 +159,8 @@ mbrtowi (wint_t *pwi, const char *s, size_t n, mbstate_t *ps)
len = mbrtowc (&w1, s, n, ps);
if (len == (size_t) -1 || len == (size_t) -2)
return len;
*pwi = w1;
if (pwi)
*pwi = w1;
/* Convert surrogate pair to wint_t value */
if (len > 0 && w1 >= 0xd800 && w1 <= 0xdbff)
{
@ -169,7 +170,8 @@ mbrtowi (wint_t *pwi, const char *s, size_t n, mbstate_t *ps)
if (len2 > 0 && w2 >= 0xdc00 && w2 <= 0xdfff)
{
len += len2;
*pwi = (((w1 & 0x3ff) << 10) | (w2 & 0x3ff)) + 0x10000;
if (pwi)
*pwi = (((w1 & 0x3ff) << 10) | (w2 & 0x3ff)) + 0x10000;
}
else
{