1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

w32: Add fallback in case the Windows console can't cope with Unicode.

* common/ttyio.c (w32_write_console): Fallback to WriteConsoleA on
error.
--

To test this switch the Windows Console to "legacy mode"

  set LANG=de
  gpg --card-edit

and enter an invalid command.  The response contains an Umlaut and old
Windows versions (and the legacy console) don't have a proper font
installed for this.  Without this patch this runs into a log_fatal
error.

The mitigation we implement is to fallback to WriteConsoleA, that is
accepting wrong encoding and to print a note about the problem.

GnuPG-bug-id: 5491
This commit is contained in:
Werner Koch 2021-06-22 11:08:05 +02:00
parent e387cc97c8
commit edfe9453be
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B

View File

@ -236,10 +236,24 @@ w32_write_console (const char *string)
n = wcslen (wstring); n = wcslen (wstring);
if (!WriteConsoleW (con.out, wstring, n, &nwritten, NULL)) if (!WriteConsoleW (con.out, wstring, n, &nwritten, NULL))
log_fatal ("WriteConsole failed: %s", w32_strerror (-1)); {
static int shown;
if (!shown)
{
shown = 1;
log_info ("WriteConsole failed: %s", w32_strerror (-1));
log_info ("Please configure a suitable font for the console\n");
}
n = strlen (string);
if (!WriteConsoleA (con.out, string, n , &nwritten, NULL))
log_fatal ("WriteConsole fallback failed: %s", w32_strerror (-1));
}
else
{
if (n != nwritten) if (n != nwritten)
log_fatal ("WriteConsole failed: %lu != %lu\n", log_fatal ("WriteConsole failed: %lu != %lu\n",
(unsigned long)n, (unsigned long)nwritten); (unsigned long)n, (unsigned long)nwritten);
}
last_prompt_len += n; last_prompt_len += n;
xfree (wstring); xfree (wstring);
} }