From: "flichtenheld (Code Review)" Date: Sun, 8 Oct 2023 10:42:41 +0000 References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="PzPauuGTVKc="; 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: , Cc: openvpn-devel , plaisthos --PzPauuGTVKc= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable flichtenheld has uploaded this change for review. ( http://gerrit.openvpn.n= et/c/openvpn/+/310?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 --- M src/openvpn/auth_token.c 1 file changed, 5 insertions(+), 11 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/10/310/2 diff --git a/src/openvpn/auth_token.c b/src/openvpn/auth_token.c index 6787ea7..28b58b0 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: 2 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-MessageType: newchange --PzPauuGTVKc= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

flichtenheld has uploaded this change for review.

View Cha= nge

generate_auth_token: simplify code

The previous code went th= rough some hoops
to avoid compiler warnings. But there is
a much easi= er way by just telling it
exactly what you want to do.

Also fix t= ypo in variable name while I'm
here.

Change-Id: Icc86334b26ba= 1fcc20f4cd03644018d1d16796e3
Signed-off-by: Frank Lichtenheld <frank@= ...2641...>
---
M src/openvpn/auth_token.c
1 file changed, 5 in= sertions(+), 11 deletions(-)

git pull ssh://gerrit.openvpn.net:29=
418/openvpn refs/changes/10/310/2
diff --git a/src/openvpn/auth_tok=
en.c b/src/openvpn/auth_token.c
index 6787ea7..28b58b0 1006= 44
--- 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_in= itial, &gc);

char *old_sessi= d =3D initial_token_copy + strlen(SESSION_ID_PREFIX);
- char *old_tsamp_initial =3D old_ses= sid + AUTH_TOKEN_SESSION_ID_LEN*8/6;
+ char *old_tstamp_initial =3D old_sessid + AUTH_TOK= EN_SESSION_ID_LEN*8/6;

/*=
* We null terminate the old token just after the sessio= n ID to let
* our base64 decode function only dec= ode 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 temporar= y variable instead of doing it in one
- * line
- */
-= uint64_t *tstamp_ptr =3D (uint64_t *) old_tstamp_decode;
= - initial_timestamp =3D *t= stamp_ptr;
+ m= emcpy(&initial_timestamp, &old_tstamp_decode, sizeof(initial_timest= amp));

+ old_tstamp_initial[0] =3D '\0'= ;;
ASSERT(openvpn_base64_decode(old_sessid, sessid= , AUTH_TOKEN_SESSION_ID_LEN) =3D=3D AUTH_TOKEN_SESSION_ID_LEN);
<= span> }

else if (!rand_bytes(sessid, AUTH_TOKEN_SE= SSION_ID_LEN))

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: 2
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: newchange
--PzPauuGTVKc=--