[Openvpn-devel,v4] ssl: Fix conversion warning in tls_prepend_opcode_v1

Message ID 20251116183336.11447-1-gert@greenie.muc.de
State New
Headers show
Series [Openvpn-devel,v4] ssl: Fix conversion warning in tls_prepend_opcode_v1 | expand

Commit Message

Gert Doering Nov. 16, 2025, 6:33 p.m. UTC
From: Frank Lichtenheld <frank@lichtenheld.com>

Document assumption with ASSERT.

Change-Id: I34584f695ddca3b3e1f2bbcb4380ac91b09c1c8d
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1298
---

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

Acked-by according to Gerrit (reflected above):
Gert Doering <gert@greenie.muc.de>

Comments

Gert Doering Nov. 16, 2025, 9:58 p.m. UTC | #1
Change makes sense.  Arne has also reviewed this, and v3/v4 take the
initial comments into account.  Smoke tested on Linux / t_client
(though I'm not sure we have tests that excercise opcode_v1).

Your patch has been applied to the master branch.

commit d926257bf4636ea43f6f5c25f5235baa25f65203
Author: Frank Lichtenheld
Date:   Sun Nov 16 19:33:30 2025 +0100

     ssl: Fix conversion warning in tls_prepend_opcode_v1

     Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
     Acked-by: Gert Doering <gert@greenie.muc.de>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1298
     Message-Id: <20251116183336.11447-1-gert@greenie.muc.de>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg34480.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c
index eb5c4fc..7b93ebc 100644
--- a/src/openvpn/ssl.c
+++ b/src/openvpn/ssl.c
@@ -3970,24 +3970,24 @@ 
     }
 }
 
+#if defined(__GNUC__) || defined(__clang__)
+#pragma GCC diagnostic pop
+#endif
+
 void
 tls_prepend_opcode_v1(const struct tls_multi *multi, struct buffer *buf)
 {
     struct key_state *ks = multi->save_ks;
-    uint8_t op;
 
     msg(D_TLS_DEBUG, __func__);
 
     ASSERT(ks);
+    ASSERT(ks->key_id <= P_KEY_ID_MASK);
 
-    op = (P_DATA_V1 << P_OPCODE_SHIFT) | ks->key_id;
+    uint8_t op = (P_DATA_V1 << P_OPCODE_SHIFT) | (uint8_t)ks->key_id;
     ASSERT(buf_write_prepend(buf, &op, 1));
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 void
 tls_prepend_opcode_v2(const struct tls_multi *multi, struct buffer *buf)
 {