From: "cron2 (Code Review)" Date: Wed, 11 Sep 2024 12:07:50 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <1a308e59c809ce6dd8ccd40ef3026cc4a7047ba7-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="8e11IdCASjk="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: generate_auth_token: simplify code List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: openvpn-devel , plaisthos --8e11IdCASjk= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/31= 0?usp=3Demail ) Change subject: generate_auth_token: simplify code ...................................................................... generate_auth_token: simplify code The previous code went through some hoops to avoid compiler warnings. But there is a much easier way by just telling it exactly what you want to do. Also fix typo in variable name while I'm here. Change-Id: Icc86334b26ba1fcc20f4cd03644018d1d16796e3 Signed-off-by: Frank Lichtenheld Acked-by: Arne Schwabe Message-Id: <20240910170005.5586-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg29= 178.html Signed-off-by: Gert Doering --- M src/openvpn/auth_token.c 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/openvpn/auth_token.c b/src/openvpn/auth_token.c index c4b59b9..192c7c2 100644 --- a/src/openvpn/auth_token.c +++ b/src/openvpn/auth_token.c @@ -182,24 +182,18 @@ char *initial_token_copy =3D string_alloc(multi->auth_token_initia= l, &gc); char *old_sessid =3D initial_token_copy + strlen(SESSION_ID_PREFIX= ); - char *old_tsamp_initial =3D old_sessid + AUTH_TOKEN_SESSION_ID_LEN= *8/6; + char *old_tstamp_initial =3D old_sessid + AUTH_TOKEN_SESSION_ID_LE= N*8/6; /* * We null terminate the old token just after the session ID to let * our base64 decode function only decode the session ID */ - old_tsamp_initial[12] =3D '\0'; - ASSERT(openvpn_base64_decode(old_tsamp_initial, old_tstamp_decode,= 9) =3D=3D 9); + old_tstamp_initial[12] =3D '\0'; + ASSERT(openvpn_base64_decode(old_tstamp_initial, old_tstamp_decode= , 9) =3D=3D 9); - /* - * Avoid old gcc (4.8.x) complaining about strict aliasing - * by using a temporary variable instead of doing it in one - * line - */ - uint64_t *tstamp_ptr =3D (uint64_t *) old_tstamp_decode; - initial_timestamp =3D *tstamp_ptr; + memcpy(&initial_timestamp, &old_tstamp_decode, sizeof(initial_time= stamp)); - old_tsamp_initial[0] =3D '\0'; + old_tstamp_initial[0] =3D '\0'; ASSERT(openvpn_base64_decode(old_sessid, sessid, AUTH_TOKEN_SESSIO= N_ID_LEN) =3D=3D AUTH_TOKEN_SESSION_ID_LEN); } else if (!rand_bytes(sessid, AUTH_TOKEN_SESSION_ID_LEN)) -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/310?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Icc86334b26ba1fcc20f4cd03644018d1d16796e3 Gerrit-Change-Number: 310 Gerrit-PatchSet: 4 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-MessageType: merged --8e11IdCASjk= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 submitted this change.

View Change

generate_auth_token: simplify code

The = previous code went through some hoops
to avoid compiler warnings. But th= ere is
a much easier way by just telling it
exactly what you want to = do.

Also fix typo in variable name while I'm
here.

Cha= nge-Id: Icc86334b26ba1fcc20f4cd03644018d1d16796e3
Signed-off-by: Frank L= ichtenheld <frank@...2641...>
Acked-by: Arne Schwabe <arne-open= vpn@...1227...>
Message-Id: <20240910170005.5586-1-gert@...1296...= >
URL: https://www.mail-archive.com/openvpn-devel@...1223...= et/msg29178.html
Signed-off-by: Gert Doering <gert@...1296...>
= ---
M src/openvpn/auth_token.c
1 file changed, 5 insertions(+), 11 de= letions(-)

diff --git a/src/openvpn/auth_token.c b/src/openvpn/auth_token.c<=
br>index c4b59b9..192c7c2 100644
--- a/src/openvpn/au= th_token.c
+++ b/src/openvpn/auth_token.c
@= @ -182,24 +182,18 @@
char *initial_token_copy =3D = string_alloc(multi->auth_token_initial, &gc);

char *old_sessid =3D initial_token_copy + strlen(SESSI= ON_ID_PREFIX);
- = char *old_tsamp_initial =3D old_sessid + AUTH_TOKEN_SESSION_ID_LEN*8/6;
+ char *old_tsta= mp_initial =3D old_sessid + AUTH_TOKEN_SESSION_ID_LEN*8/6;
=
/*
* We null terminate= the old token just after the session ID to let
*= our base64 decode function only decode the session ID
= */
- old_t= samp_initial[12] =3D '\0';
- ASSERT(openvpn_base64_decode(old_tsamp_initial, old_ts= tamp_decode, 9) =3D=3D 9);
+ old_tstamp_initial[12] =3D '\0';
+ ASSERT(openvpn_base64_decode(ol= d_tstamp_initial, old_tstamp_decode, 9) =3D=3D 9);
=
- /*
- * Avoid old gcc (4.8.x) compla= ining about strict aliasing
- * by using a temporary variable instead of doing it in one
- * line<= br>- */
- uint64_t *tstamp_ptr =3D (uint6= 4_t *) old_tstamp_decode;
- initial_timestamp =3D *tstamp_ptr;
+ memcpy(&initial_timestamp, &old_= tstamp_decode, sizeof(initial_timestamp));

- old_tsamp_initial[0] =3D = 9;\0';

+ o= ld_tstamp_initial[0] =3D '\0';
ASSERT(open= vpn_base64_decode(old_sessid, sessid, AUTH_TOKEN_SESSION_ID_LEN) =3D=3D AUT= H_TOKEN_SESSION_ID_LEN);
}
else i= f (!rand_bytes(sessid, AUTH_TOKEN_SESSION_ID_LEN))
<= br>

To view, visit change 310. To unsubscribe, or for help writing mail = filters, visit settings.=

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Icc86334b26ba1fcc20f4cd03644= 018d1d16796e3
Gerrit-Change-Number: 310
Gerrit-PatchSet: 4
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: merged
--8e11IdCASjk=--