Change in openvpn[master]: mingw: avoid C99 "hh" scanf length modifier
A message that is not in the archive (sent off-list or not yet received): gerrit.1782500411000.I6595695ab6401047d498d530f8739686880bea3a@gerrit.openvpn.net
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.
---
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
src/openvpn/crypto.c +3 -3
@@ -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) {
src/openvpn/cryptoapi.c +3 -1
@@ -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
Attention is currently required from: d12fk.
plaisthos has posted comments on this change by d12fk. ( http://gerrit.openvpn.net/c/openvpn/+/1733?usp=email )
Change subject: mingw: avoid C99 "hh" scanf length modifier
......................................................................
Patch Set 2:
(1 comment)
File src/openvpn/crypto.c:
http://gerrit.openvpn.net/c/openvpn/+/1733/comment/3dd58ae2_6f546134?usp=email :
PS2, Line 1477: ASSERT(sscanf((const char *)hex_byte, "%" SCNx8, &u) == 1);
I am confused about this one. Does that mean we have a toolchain that defines SCNx8 as hh but then cannot work with that?
--
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: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6595695ab6401047d498d530f8739686880bea3a
Gerrit-Change-Number: 1733
Gerrit-PatchSet: 2
Gerrit-Owner: d12fk <[email protected]>
Gerrit-Reviewer: plaisthos <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: d12fk <[email protected]>
Gerrit-Comment-Date: Wed, 01 Jul 2026 11:30:47 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Attention is currently required from: plaisthos.
d12fk has posted comments on this change by d12fk. ( http://gerrit.openvpn.net/c/openvpn/+/1733?usp=email )
Change subject: mingw: avoid C99 "hh" scanf length modifier
......................................................................
Patch Set 2:
(1 comment)
File src/openvpn/crypto.c:
http://gerrit.openvpn.net/c/openvpn/+/1733/comment/a49a3e2c_5f20a54c?usp=email :
PS2, Line 1477: ASSERT(sscanf((const char *)hex_byte, "%" SCNx8, &u) == 1);
Quoted 1 line
I am confused about this one. […]
Certainly true for MinGW on 26.04. There is a uLibc, that supports %hhx. Unfortunately MinGW isn't linked with it, but MSVCRT, which doesn't support %hhx. That is true for Ubuntu. Debian also provides MinGW with uLibc. Ubunutu doesn't have those packages for some reason. So the situation is that the headers are shared (it seems) between both libc implementations, while the compiler is hard liked to one of them. Which one the headers do not seem to care about much.
There seems to be some compile time flag, which makes MinGW use the glibc scanf/printf format string parser, which does support C99 as well, but when you have to recompile going uLibc is the saner approach.
Even more sane is to skip on use of unsupported C99 features until this mess is resolved in all distros. uLibc seems to be the standard today already with MSVC.
--
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: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6595695ab6401047d498d530f8739686880bea3a
Gerrit-Change-Number: 1733
Gerrit-PatchSet: 2
Gerrit-Owner: d12fk <[email protected]>
Gerrit-Reviewer: plaisthos <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]>
Gerrit-Comment-Date: Thu, 02 Jul 2026 22:09:34 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: plaisthos <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Attention is currently required from: d12fk, plaisthos.
flichtenheld has posted comments on this change by d12fk. ( http://gerrit.openvpn.net/c/openvpn/+/1733?usp=email )
Change subject: mingw: avoid C99 "hh" scanf length modifier
......................................................................
Patch Set 2: Code-Review+2
(1 comment)
File src/openvpn/crypto.c:
http://gerrit.openvpn.net/c/openvpn/+/1733/comment/7e2808a9_614d1954?usp=email :
PS2, Line 1477: ASSERT(sscanf((const char *)hex_byte, "%" SCNx8, &u) == 1);
Quoted 1 line
Certainly true for MinGW on 26.04. There is a uLibc, that supports %hhx. […]
After researching this myself a bit I agree with both the sentiment that this is a mess and with Heiko's assessment that a work-around is currently the easiest solution.
--
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: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6595695ab6401047d498d530f8739686880bea3a
Gerrit-Change-Number: 1733
Gerrit-PatchSet: 2
Gerrit-Owner: d12fk <[email protected]>
Gerrit-Reviewer: flichtenheld <[email protected]>
Gerrit-Reviewer: plaisthos <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]>
Gerrit-Attention: d12fk <[email protected]>
Gerrit-Comment-Date: Fri, 03 Jul 2026 11:53:04 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: plaisthos <[email protected]>
Comment-In-Reply-To: d12fk <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
PATCH v2 1/1 mingw: avoid C99 "hh" scanf length modifier
In reply to a message not in the archiveFrom: Heiko Hund <[email protected]>
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.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1733
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1733
This mail reflects revision 2 of this Change.
Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <[email protected]>
src/openvpn/crypto.c +3 -3
@@ -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) {
src/openvpn/cryptoapi.c +3 -1
@@ -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; }
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
PATCH v2 1/1 mingw: avoid C99 "hh" scanf length modifier
In reply to a message not in the archiveFrom: Heiko Hund <[email protected]>
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.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1733
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1733
This mail reflects revision 2 of this Change.
Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <[email protected]>
src/openvpn/crypto.c +3 -3
@@ -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) {
src/openvpn/cryptoapi.c +3 -1
@@ -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; }
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
[Openvpn-devel] [PATCH applied] Re: mingw: avoid C99 hh scanf length modifier
I find the whole explanation behind this highly confusing, and I find it even more amazing that we have no "parse_hex_byte_ex()" function in all of our codebase and have to resort to scanf()... - but whatever, the new code is not much uglier than before, the scanf() actually more readable (because no macro involved), and it works on all MinGW versions...
parse_hexstring() comes with a unit test, and that still passes, so "tested well enough" :-) - also compile tested with whatever MinGW version I have here + GHA.
Your patch has been applied to the master and release/2.7 branch (long-term compat)
commit 035a88f97b1ffdc88497faeaa0aeb8a72e1eaf4f (master) commit 326bd05d3db9be075091cd12b7a7c7c798ef9a7e (release/2.7)
Author: Heiko Hund Date: Wed Jul 8 20:56:53 2026 +0200
mingw: avoid C99 hh scanf length modifier
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1733
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg37544.html
--
kind regards,
Gert Doering
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
cron2 has uploaded a new patch set (#3) to the change originally created by d12fk. ( http://gerrit.openvpn.net/c/openvpn/+/1733?usp=email )
The following approvals got outdated and were removed:
Code-Review+2 by flichtenheld
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.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1733
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg37544.html
---
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/3
src/openvpn/crypto.c +3 -3
@@ -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) {
src/openvpn/cryptoapi.c +3 -1
@@ -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: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6595695ab6401047d498d530f8739686880bea3a
Gerrit-Change-Number: 1733
Gerrit-PatchSet: 3
Gerrit-Owner: d12fk <[email protected]>
Gerrit-Reviewer: flichtenheld <[email protected]>
Gerrit-Reviewer: plaisthos <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1733?usp=email )
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.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1733
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg37544.html
---
M src/openvpn/crypto.c
M src/openvpn/cryptoapi.c
2 files changed, 6 insertions(+), 4 deletions(-)
src/openvpn/crypto.c +3 -3
@@ -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) {
src/openvpn/cryptoapi.c +3 -1
@@ -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: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6595695ab6401047d498d530f8739686880bea3a
Gerrit-Change-Number: 1733
Gerrit-PatchSet: 3
Gerrit-Owner: d12fk <[email protected]>
Gerrit-Reviewer: flichtenheld <[email protected]>
Gerrit-Reviewer: plaisthos <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel