[Openvpn-devel,3/5] src/openvpn/auth_token.c: handle strdup errors

Message ID 20240708210912.566-4-chipitsine@gmail.com
State New
Headers show
Series handle strdup errors | expand

Commit Message

Илья Шипицин July 8, 2024, 9:08 p.m. UTC
Signed-off-by: Ilia Shipitsin <chipitsine@gmail.com>
---
 src/openvpn/auth_token.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Patch

diff --git a/src/openvpn/auth_token.c b/src/openvpn/auth_token.c
index 6787ea7d..2278afe6 100644
--- a/src/openvpn/auth_token.c
+++ b/src/openvpn/auth_token.c
@@ -260,6 +260,10 @@  generate_auth_token(const struct user_pass *up, struct tls_multi *multi)
     /* free the auth-token if defined, we will replace it with a new one */
     free(multi->auth_token);
     multi->auth_token = strdup((char *)BPTR(&session_token));
+    if (!multi->auth_token)
+    {
+        msg( M_FATAL, "Failed allocate memory for multi->auth_token");
+    }
 
     dmsg(D_SHOW_KEYS, "Generated token for client: %s (%s)",
          multi->auth_token, up->username);
@@ -271,6 +275,10 @@  generate_auth_token(const struct user_pass *up, struct tls_multi *multi)
          * and timestamp in updates
          */
         multi->auth_token_initial = strdup(multi->auth_token);
+        if (!multi->auth_token_initial)
+        {
+            msg( M_FATAL, "Failed allocate memory for multi->auth_token_initial");
+        }
     }
 
     gc_free(&gc);