public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin/main] Cygwin: mbrtowi: fix segfault when pwi is NULL
Date: Wed, 19 Apr 2023 08:16:00 +0000 (GMT)	[thread overview]
Message-ID: <20230419081600.D0D70385840E@sourceware.org> (raw)

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
 	{

                 reply	other threads:[~2023-04-19  8:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230419081600.D0D70385840E@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).