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/cygwin-3_5-branch] Cygwin: globify: read full 32 bit character
Date: Tue,  9 Apr 2024 20:36:50 +0000 (GMT)	[thread overview]
Message-ID: <20240409203650.26B053858D39@sourceware.org> (raw)

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

commit 14216d5442e04f23f20318b434b3f2bc4c43ca90
Author:     Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Tue Apr 9 22:30:03 2024 +0200
Commit:     Corinna Vinschen <corinna@vinschen.de>
CommitDate: Tue Apr 9 22:30:34 2024 +0200

    Cygwin: globify: read full 32 bit character
    
    While commit 0321fb573654 ("Cygwin: glob: convert wchar_t to wint_t")
    switched the entire glob mechanism from wchar_t to wint_t, the globify
    function calling glob on a DOS command line did not catch up and only
    checked for the next character constituting a 16 bit wchar_t. This
    broke reading surrogate pairs from incoming DOS command lines if the
    string had to go through glob(3).
    
    Check for an entire 32 bit unicode char instead.
    
    Fixes: 0321fb573654 ("Cygwin: glob: convert wchar_t to wint_t")
    Reported-by: David Allsopp <david@tarides.com>
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/dcrt0.cc      | 3 ++-
 winsup/cygwin/release/3.5.4 | 4 ++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index ea6a18b51d70..ff7e6ec50f54 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -236,12 +236,13 @@ globify (char *word, char **&argv, int &argc, int &argvlen)
 	char quote = *s;
 	while (*++s && *s != quote)
 	  {
+	    mbstate_t mbs = { 0 };
 	    if (dos_spec || *s != '\\')
 	      /* nothing */;
 	    else if (s[1] == quote || s[1] == '\\')
 	      s++;
 	    *p++ = '\\';
-	    size_t cnt = isascii (*s) ? 1 : mbtowc (NULL, s, MB_CUR_MAX);
+	    size_t cnt = isascii (*s) ? 1 : mbrtowi (NULL, s, MB_CUR_MAX, &mbs);
 	    if (cnt <= 1 || cnt == (size_t)-1)
 	      *p++ = *s;
 	    else
diff --git a/winsup/cygwin/release/3.5.4 b/winsup/cygwin/release/3.5.4
index e2bd025317e9..e1909865f362 100644
--- a/winsup/cygwin/release/3.5.4
+++ b/winsup/cygwin/release/3.5.4
@@ -4,3 +4,7 @@ Fixes:
 - Fix regression in 3.5.3 which fails to open files for stat(2) if the
   file is opened exclusively by another process.
   Addresses: https://cygwin.com/pipermail/cygwin/2024-April/255811.html
+
+- Fix regression introduced in 3.5.0 when reading surrogate pairs (i.e.,
+  unicode chars >= 0x10000) from the DOS command line.  Addresses:
+  https://cygwin.com/pipermail/cygwin/2024-April/255807.html

                 reply	other threads:[~2024-04-09 20:36 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=20240409203650.26B053858D39@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).