diff options
author | Chun-wei Fan <fanchunwei@src.gnome.org> | 2019-03-18 14:55:00 +0800 |
---|---|---|
committer | Claudio Saavedra <csaavedra@igalia.com> | 2019-03-30 09:55:25 +0000 |
commit | 8a7174ce7133959e9cf5d9538b8557c4545fd53b (patch) | |
tree | 7a528a23eedf298135037dfca76f5ddeb455088e | |
parent | a4b5e3a1e5447475f711f3d34bf92eb58a99d1f5 (diff) | |
download | libsoup-8a7174ce7133959e9cf5d9538b8557c4545fd53b.tar.gz |
soup-auth-ntlm.c: Fix running on older Visual Studio CRT
This checks on Windows whether we have __USE_MINGW_ANSI_STDIO
defined for MinGW builds or whether we are building with Visual Studio
2015 or later, as sscanf(..., "%2hhx", ...) would either fail to build
or will fail to run correctly if either of these conditions do not hold
on Windows, as the stock Windows (pre-Visual Studio 2015) CRT does not
support the 'hh' modifier, as it is C99.
If the sscanf() implementation on Windows does not support the 'hh'
modifier, use a workaround so that we obtain the correct values we need
from sscanf().
-rw-r--r-- | libsoup/soup-auth-ntlm.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/libsoup/soup-auth-ntlm.c b/libsoup/soup-auth-ntlm.c index 34d54601..a1103697 100644 --- a/libsoup/soup-auth-ntlm.c +++ b/libsoup/soup-auth-ntlm.c @@ -812,7 +812,19 @@ calc_hmac_md5 (unsigned char *hmac, const guchar *key, gsize key_sz, const gucha hex_pos = hmac_hex; for (count = 0; count < HMAC_MD5_LENGTH; count++) { + unsigned int tmp_hmac; + + /* The 'hh' sscanf format modifier is C99, so we enable it on + * non-Windows or if __USE_MINGW_ANSI_STDIO is enabled or` + * if we are building on Visual Studio 2015 or later + */ +#if !defined (G_OS_WIN32) || (__USE_MINGW_ANSI_STDIO == 1) || (_MSC_VER >= 1900) sscanf(hex_pos, "%2hhx", &hmac[count]); +#else + sscanf(hex_pos, "%2x", &tmp_hmac); + hmac[count] = (guint8)tmp_hmac; +#endif + hex_pos += 2; } g_free(hmac_hex); |