Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows error message has wrong encoding #319

Closed
selvanair opened this issue Apr 17, 2023 · 1 comment
Closed

Windows error message has wrong encoding #319

selvanair opened this issue Apr 17, 2023 · 1 comment

Comments

@selvanair
Copy link
Contributor

Originally posted by @mastezont in OpenVPN/openvpn-gui#491 (comment)

Windows 7, OpenVPN version 2.6.3, OpenVPN GUI 11.41.0.0, OS language and OpenVPN GUI Russian. In the "display status" window, part of the message in Russian with the wrong character set (highlighted in the screenshot). If you select "show log" and open it in Notepad++, it shows character set Cyrillic Macintosh instead of the usual Cyrillic Windows-1251, while the word "Элемент" is displayed incorrectly as "Ёлемент" (highlighted in the screenshot).
This error has appeared since version 2.6.0, if memory serves me correctly.

sshot-4
sshot-5

Originally posted by @mastezont in OpenVPN/openvpn-gui#491 (comment)

@selvanair
Copy link
Contributor Author

selvanair commented Apr 17, 2023

In error.c in openvpn we have

/* format a windows error message */
    {
        char message[256];
        struct buffer out = alloc_buf_gc(256, gc);
        const int status =  FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM
            | FORMAT_MESSAGE_ARGUMENT_ARRAY, NULL, errnum, 0,
            message, sizeof(message), NULL);

This will call the ANSI version and return "message" using the current code page while the implicit assumption is that all strings are unicode in utf-8 encoding. I think we should call FormatMessageW() here and convert the result to utf-8.

cron2 pushed a commit that referenced this issue May 4, 2023
- We assume that all text passed to the management interface
  and written to log file are in Unicode (UTF-8). This is broken by
  the use of the ANSI version of FormatMessage() for Windows error
  messages. Fix by using FormatMessageW() and converting the UTF-16
  result to UTF-8.

v2: assign return value of FormatMessageW() to DWORD, not int

Github: fixes #319

Signed-off-by: Selva Nair <[email protected]>
Acked-by: Frank Lichtenheld <[email protected]>
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg26598.html
Signed-off-by: Gert Doering <[email protected]>
(cherry picked from commit fed6764)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant