]> The Tcpdump Group git mirrors - libpcap/commitdiff
Force FormatMessageA().
authorGuy Harris <[email protected]>
Thu, 19 Jul 2018 10:07:55 +0000 (03:07 -0700)
committerGuy Harris <[email protected]>
Fri, 20 Jul 2018 09:37:28 +0000 (02:37 -0700)
Internally, we're using encodings in which ASCII characters are
represented in a single byte, so message strings must be "ANSI", not
"Unicode".  Yes, that means they'll be in the current code page, which
isn't necessarily - and probably isn't - UTF-8, but Windows really
doesn't seem to provide much support for UTF-8 as a representation of
Unicode (the current code page isn't necessarily 65001, i.e. UTF-8,
especially given that some software appears to have problems with that
code page on at least some versions of Windows).

See GitHub issue pynetwork/pypcap#64.

(cherry picked from commit a5341c3b81a4d7f00b5318c6d8fa8673eda81611)

pcap.c
rpcapd/daemon.c
rpcapd/win32-svc.c
sockutils.c

diff --git a/pcap.c b/pcap.c
index 67e5467102058afb04899c2558767f50b01f1319..942c472a36545654475f9e6b074de061c1b64a3d 100644 (file)
--- a/pcap.c
+++ b/pcap.c
@@ -3251,7 +3251,7 @@ pcap_win32_err_to_str(DWORD error, char *errbuf)
        size_t errlen;
        char *p;
 
-       FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, errbuf,
+       FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, errbuf,
            PCAP_ERRBUF_SIZE, NULL);
 
        /*
index b6815ac7f02c5acde935673be1247bf51ce8a774..4bf42fde849ecf2ece8a74882c82976ad919ef74 100644 (file)
@@ -1143,7 +1143,7 @@ daemon_AuthUserPwd(char *username, char *password, char *errbuf)
                int error;
 
                error = GetLastError();
-               FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, errbuf,
+               FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, errbuf,
                        PCAP_ERRBUF_SIZE, NULL);
 
                return -1;
@@ -1156,7 +1156,7 @@ daemon_AuthUserPwd(char *username, char *password, char *errbuf)
                int error;
 
                error = GetLastError();
-               FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, errbuf,
+               FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, errbuf,
                        PCAP_ERRBUF_SIZE, NULL);
 
                CloseHandle(Token);
index b59437812f2adbf34380507b97df3190247f64aa..8cc7dc92193ee8b6fe6119d3491fddde5906f19a 100644 (file)
@@ -68,7 +68,7 @@ void svc_geterr(char *str)
        int val;
 
        val = GetLastError();
-       FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS |
+       FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS |
                                  FORMAT_MESSAGE_MAX_WIDTH_MASK,
                                  NULL, val, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                                  (LPSTR) string, PCAP_ERRBUF_SIZE, NULL);
index 018ac026e527b2fff7f4e6ca30b9ccbd9ff50d5d..ef3fe764973c8b3283766e37127a3d39ec4829de 100644 (file)
@@ -132,12 +132,12 @@ void sock_fmterror(const char *caller, int errcode, char *errbuf, int errbuflen)
 {
 #ifdef _WIN32
        int retval;
-       TCHAR message[SOCK_ERRBUF_SIZE];        /* It will be char (if we're using ascii) or wchar_t (if we're using unicode) */
+       char message[SOCK_ERRBUF_SIZE]; /* We're forcing "ANSI" */
 
        if (errbuf == NULL)
                return;
 
-       retval = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS |
+       retval = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS |
                FORMAT_MESSAGE_MAX_WIDTH_MASK,
                NULL, errcode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                message, sizeof(message) / sizeof(TCHAR), NULL);