[Openvpn-devel,v7] buffer: Clarify usage of char_class

Message ID 20260304105007.14485-1-gert@greenie.muc.de
State New
Headers show
Series [Openvpn-devel,v7] buffer: Clarify usage of char_class | expand

Commit Message

Gert Doering March 4, 2026, 10:50 a.m. UTC
From: Frank Lichtenheld <frank@lichtenheld.com>

Silence compiler warnings due to conversion from
char to unsigned char. In this case we actually
depend on this conversion.

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

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

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

Comments

Gert Doering March 4, 2026, 11:58 a.m. UTC | #1
Easy and straightforward enough, plus extra documentation :-)

I have not tested this beyond BB, but given the nature of the change
and that all these casts have been (implicitly) there already, I do not
expect surprises.  Nightly t_server tests will complain if I'm wrong.

Your patch has been applied to the master branch.

commit 9735675529450467ff5ad5e6500caef4d225b17b
Author: Frank Lichtenheld
Date:   Wed Mar 4 11:50:01 2026 +0100

     buffer: Clarify usage of char_class

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


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/buffer.c b/src/openvpn/buffer.c
index dd74b38..12a8ff9 100644
--- a/src/openvpn/buffer.c
+++ b/src/openvpn/buffer.c
@@ -559,7 +559,7 @@ 
         {
             break;
         }
-        if (char_class(*last, CC_CRLF | CC_NULL))
+        if (char_class((unsigned char)*last, CC_CRLF | CC_NULL))
         {
             if (!buf_inc_len(buf, -1))
             {
@@ -876,6 +876,14 @@ 
  * Classify and mutate strings based on character types.
  */
 
+/* Note 1: This functions depends on getting an unsigned
+   char. Both the is*() functions and our own checks expect it
+   this way.
+   Note 2: For CC_PRINT we just accept everything >= 32, so
+   if we ingest non-ASCII UTF-8 we will classify it as
+   printable since it will be >= 128. Other encodings are
+   not officially supported.
+*/
 bool
 char_class(const unsigned char c, const unsigned int flags)
 {
@@ -1019,7 +1027,8 @@ 
 static inline bool
 char_inc_exc(const char c, const unsigned int inclusive, const unsigned int exclusive)
 {
-    return char_class(c, inclusive) && !char_class(c, exclusive);
+    return char_class((unsigned char)c, inclusive)
+           && !char_class((unsigned char)c, exclusive);
 }
 
 bool