Skip to contentSkip to conversation

Exit if a proper message instead of segfault on Android without management

PATCH In review Arne Schwabe 2 participants 2 messages Feb 20, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Exit if a proper message instead of segfault on Android without management

The Android implementation is relying on the management interface to be always available. Trying to run the Android binary without the mangament interface outside the app leads to a segfault. Exit with a FATAL error instead.

---
 src/openvpn/manage.c | 4 ++++
 src/openvpn/socket.c | 5 +++++
 2 files changed, 9 insertions(+)
src/openvpn/manage.c +4 -0
index 3ea1992b0..db88e3479 100644
@@ -2192,6 +2192,10 @@ man_recv_with_fd(int fd, void *ptr, size_t nbytes, int flags, int *recvfd)
 bool
 management_android_control(struct management *man, const char *command, const char *msg)
 {
+    if (!man)
+    {
+        msg(M_FATAL, "Required management interface not available.");
+    }
     struct user_pass up;
     CLEAR(up);
     strncpy(up.username, msg, sizeof(up.username)-1);
src/openvpn/socket.c +5 -0
index 42d953390..eff21ca56 100644
@@ -1161,6 +1161,11 @@ create_socket(struct link_socket *sock, struct addrinfo *addr)
 static void
 protect_fd_nonlocal(int fd, const struct sockaddr *addr)
 {
+    if (!management)
+    {
+        msg(M_FATAL, "Required management interface not available.")
+    }
+
     /* pass socket FD to management interface to pass on to VPNService API
      * as "protected socket" (exempt from being routed into tunnel)
      */
Signature · 1 line
2.37.1 (Apple Git-137.1)
Acked-by on v1 1/1
#1 lore raw

This code is all inside #ifdef TARGET_ANDROID, so I didn't test anything - but it looks all reasonable.

Your patch has been applied to the master and release/2.6 branch.

commit 3132bead497deca24dc638e151bf7194df6f4884 (master) commit d0c1abb4dee233834de540932ddcaef209696e79 (release/2.6)

Author: Arne Schwabe
Date:   Mon Feb 20 14:14:24 2023 +0100
     Exit if a proper message instead of segfault on Android without management

     Signed-off-by: Arne Schwabe <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg26288.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering