[Openvpn-devel,v1] Add cast to BN_num_bytes return value for AWS-LC

Message ID 20261202115302.879-1-gert@greenie.muc.de
State New
Headers
Series [Openvpn-devel,v1] Add cast to BN_num_bytes return value for AWS-LC |

Commit Message

Gert Doering Dec. 2, 2026, 11:52 a.m. UTC
  From: Max Fillinger <maximilian.fillinger@sentyron.com>

The return value of BN_num_bytes is int in OpenSSL but unsigned int in
AWS-LC. This caused a compiler warning, and causes builds with
-Werror=sign-conversion to fail. This commit casts the return value to
unsigned int.

Change-Id: I24d3e80182e4121b3d84c3bdc07d3172f872da8f
Signed-off-by: Max Fillinger <maximilian.fillinger@sentyron.com>
Acked-by: Razvan Cojocaru <razvanc@mailbox.org>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2389
---

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/+/2389
This mail reflects revision 1 of this Change.

Acked-by according to Gerrit (reflected above):
Razvan Cojocaru <razvanc@mailbox.org>
  

Comments

Gert Doering Dec. 2, 2026, 12:28 p.m. UTC | #1
Good & integer-safe patch for the AWS LC annoyance... thanks.

Since the original patch went to "all the branches", it makes sense to
fix this too ("considered part of the original bugfix") - even though
I assume nobody would build 2.6 with AWS-LC *and* -Werror.

Our GH Action setup tests 2.7 and master on aws-lc, and that is now
back to "all green".

Your patch has been applied to the master, release/2.7, release/2.6 branch.

The list archive is acting up again, so referring to lore.kernel.org.

commit 731de6fed960f5a874ba1802ec261717485833b1 (master)
commit 9933a6ab1234888a9a4ec3b8cc5419463d49f9a4 (release/2.7)
commit f72eb19b1d9b8689af9eb2c1370c9dbc9e8357ac (release/2.6)
Author: Max Fillinger
Date:   Wed Dec 2 12:52:56 2026 +0100

     Add cast to BN_num_bytes return value for AWS-LC

     Signed-off-by: Max Fillinger <maximilian.fillinger@sentyron.com>
     Acked-by: Razvan Cojocaru <razvanc@mailbox.org>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2389
     Message-Id: <20261202115302.879-1-gert@greenie.muc.de>
     URL: https://lore.kernel.org/openvpn-devel/20261202115302.879-1-gert@greenie.muc.de
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering
  

Patch

diff --git a/src/openvpn/ssl_verify_openssl.c b/src/openvpn/ssl_verify_openssl.c
index ee29691..ab3c872 100644
--- a/src/openvpn/ssl_verify_openssl.c
+++ b/src/openvpn/ssl_verify_openssl.c
@@ -61,7 +61,11 @@ 
     BIGNUM *bn_serial = ASN1_INTEGER_to_BN(asn1_i, NULL);
     if (bn_serial != NULL)
     {
-        int size = BN_num_bytes(bn_serial);
+        /* Cast the return value of BN_num_bytes to unsigned int because it is
+         * int in OpenSSL and unsigned int in AWS-LC. The return value of
+         * BN_num_bytes should never be negative, and if it is, the cast will
+         * turn it into an unacceptably large value which will fail this check. */
+        unsigned int size = (unsigned int)BN_num_bytes(bn_serial);
         size_ok = size <= MAX_SERIAL_SIZE;
     }
     BN_free(bn_serial);