summaryrefslogtreecommitdiffstats
path: root/common/ttyio.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2021-06-22 11:08:05 +0200
committerWerner Koch <wk@gnupg.org>2021-06-22 11:12:28 +0200
commitedfe9453be5f8ba374da0ab860be863d66965c56 (patch)
treef8e2e563a0608eecf745199954f47109dd5a1ea0 /common/ttyio.c
parentscd:p15: Prepare AODF parsing for other authentication types. (diff)
downloadgnupg2-edfe9453be5f8ba374da0ab860be863d66965c56.tar.xz
gnupg2-edfe9453be5f8ba374da0ab860be863d66965c56.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
Diffstat (limited to 'common/ttyio.c')
-rw-r--r--common/ttyio.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/common/ttyio.c b/common/ttyio.c
index 15f7a0203..f77c053e2 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);
}