Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1733?usp=email

to review the following change.


Change subject: mingw: avoid C99 "hh" scanf length modifier
......................................................................

mingw: avoid C99 "hh" scanf length modifier

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 <[email protected]>
---
M src/openvpn/crypto.c
M src/openvpn/cryptoapi.c
2 files changed, 6 insertions(+), 4 deletions(-)



  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/33/1733/1

diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c
index 7954e8a..db84a33 100644
--- a/src/openvpn/crypto.c
+++ b/src/openvpn/crypto.c
@@ -1473,9 +1473,9 @@
                     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)
                         {
diff --git a/src/openvpn/cryptoapi.c b/src/openvpn/cryptoapi.c
index bf80bbd..0f95ab7 100644
--- a/src/openvpn/cryptoapi.c
+++ b/src/openvpn/cryptoapi.c
@@ -169,10 +169,12 @@
             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;
 }

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1733?usp=email
To unsubscribe, or for help writing mail filters, visit 
http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6595695ab6401047d498d530f8739686880bea3a
Gerrit-Change-Number: 1733
Gerrit-PatchSet: 1
Gerrit-Owner: d12fk <[email protected]>
Gerrit-Reviewer: plaisthos <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Reply via email to