public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin/main] Cygwin: mbrtowi: fix segfault when pwi is NULL
@ 2023-04-19  8:16 Corinna Vinschen
  0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2023-04-19  8:16 UTC (permalink / raw)
  To: cygwin-cvs

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=53f7fb20a064fec180291a497d11eb66fe6172e6

commit 53f7fb20a064fec180291a497d11eb66fe6172e6
Author:     David McFarland <corngood@gmail.com>
AuthorDate: Tue Apr 18 17:05:34 2023 -0300
Commit:     Corinna Vinschen <corinna@vinschen.de>
CommitDate: Wed Apr 19 10:14:46 2023 +0200

    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: 60c25da90d01 ("Cygwin: mbrtowi: define replacement for mbrtowc, returning UTF-32 value")
    Signed-off-by: David McFarland <corngood@gmail.com>

Diff:
---
 winsup/cygwin/strfuncs.cc | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/winsup/cygwin/strfuncs.cc b/winsup/cygwin/strfuncs.cc
index 57abf25649ec..76b7216cc3a2 100644
--- a/winsup/cygwin/strfuncs.cc
+++ b/winsup/cygwin/strfuncs.cc
@@ -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
 	{

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-04-19  8:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-19  8:16 [newlib-cygwin/main] Cygwin: mbrtowi: fix segfault when pwi is NULL Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).