]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
mingw: avoid C99 "hh" scanf length modifier
authorHeiko Hund <heiko@ist.eigentlich.net>
Wed, 8 Jul 2026 18:56:53 +0000 (20:56 +0200)
committerGert Doering <gert@greenie.muc.de>
Thu, 23 Jul 2026 18:25:33 +0000 (20:25 +0200)
read_key_file() and parse_hexstring() parse hex bytes with sscanf()
using the C99 "hh" length modifier, storing directly into an octet.

This is not portable to the legacy MSVCRT runtime that Ubuntu
resolute's (26.04) mingw toolchain links against.

Scan into an unsigned int and cast to the octet instead. The field width
caps the value at 0xFF, so the narrowing cast cannot lose data.

Change-Id: I6595695ab6401047d498d530f8739686880bea3a
Signed-off-by: Heiko Hund <heiko@ist.eigentlich.net>
Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1733
Message-Id: <20260708185659.10219-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg37544.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/crypto.c
src/openvpn/cryptoapi.c

index 3d79fe56166d413f3285dc7fa2c2243469d46991..ee43d654f7c5c5226539d385650ece387f1fc999 100644 (file)
@@ -1473,9 +1473,9 @@ read_key_file(struct key2 *key2, const char *file, const unsigned int flags)
                     hex_byte[hb_index++] = c;
                     if (hb_index == 2)
                     {
-                        uint8_t u;
-                        ASSERT(sscanf((const char *)hex_byte, "%" SCNx8, &u) == 1);
-                        *out++ = u;
+                        unsigned int u;
+                        ASSERT(sscanf((const char *)hex_byte, "%2x", &u) == 1);
+                        *out++ = (uint8_t)u;
                         hb_index = 0;
                         if (++count == keylen)
                         {
index bf80bbd01c9a804d37323ec0bf2402d1bc2acf0f..0f95ab7fd1133a3e0405adf96e4abc658ec8da75 100644 (file)
@@ -169,10 +169,12 @@ parse_hexstring(const char *p, unsigned char *arr, DWORD capacity)
             break;
         }
 
-        if (!isxdigit(p[0]) || !isxdigit(p[1]) || sscanf(p, "%2hhx", &arr[i++]) != 1)
+        unsigned int b;
+        if (!isxdigit(p[0]) || !isxdigit(p[1]) || sscanf(p, "%2x", &b) != 1)
         {
             return 0;
         }
+        arr[i++] = (unsigned char)b;
     }
     return i;
 }