aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2021-06-22 09:08:05 +0000
committerWerner Koch <[email protected]>2021-06-22 09:08:05 +0000
commite94dfa21d2c17b590122d55468f68e8ab72e4193 (patch)
treef90c0901dc6452948e9e03ff8ca4055fdb37ed40
parentdirmngr: Fix regression in KS_GET for mail address pattern. (diff)
downloadgnupg-e94dfa21d2c17b590122d55468f68e8ab72e4193.tar.gz
gnupg-e94dfa21d2c17b590122d55468f68e8ab72e4193.zip
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
-rw-r--r--common/ttyio.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/common/ttyio.c b/common/ttyio.c
index c385700de..c31081745 100644
--- a/common/ttyio.c
+++ b/common/ttyio.c
@@ -236,10 +236,24 @@ w32_write_console (const char *string)
n = wcslen (wstring);
if (!WriteConsoleW (con.out, wstring, n, &nwritten, NULL))
- log_fatal ("WriteConsole failed: %s", w32_strerror (-1));
- if (n != nwritten)
- log_fatal ("WriteConsole failed: %lu != %lu\n",
- (unsigned long)n, (unsigned long)nwritten);
+ {
+ 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)
+ log_fatal ("WriteConsole failed: %lu != %lu\n",
+ (unsigned long)n, (unsigned long)nwritten);
+ }
last_prompt_len += n;
xfree (wstring);
}