[libsoup/windows.prec99] soup-auth-ntlm.c: Fix running on older Visual Studio CRT



commit 48830c76fa2309cd4a0e839667e2fd4492790e21
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Mon Mar 18 14:55:00 2019 +0800

    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().

 libsoup/soup-auth-ntlm.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
---
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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]