diff mbox series

[14/90] connection: Check 'service' parameter for null.

Message ID 20231206235056.322578-15-gerickson@nuovations.com (mailing list archive)
State Not Applicable, archived
Headers show
Series Add Gateway Low-priority Default Routes for Non-default Services | expand

Commit Message

Grant Erickson Dec. 6, 2023, 11:49 p.m. UTC
From: Grant Erickson <erick205@umn.edu>

In '__connman_connection_gateway_add', as an internal, cross-module
function, check that the 'service' parameter is not null. If it is,
return -EINVAL.
---
 src/connection.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/src/connection.c b/src/connection.c
index e80443c02a5a..e6a6ea42dc59 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1830,8 +1830,7 @@  int __connman_connection_gateway_add(struct connman_service *service,
 	struct gateway_data *new_gateway = NULL;
 	enum connman_ipconfig_type type4 = CONNMAN_IPCONFIG_TYPE_UNKNOWN,
 		type6 = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
-	enum connman_service_type service_type =
-					connman_service_get_type(service);
+	enum connman_service_type service_type;
 	int index;
 	g_autofree char *interface = NULL;
 	int err = 0;
@@ -1842,12 +1841,17 @@  int __connman_connection_gateway_add(struct connman_service *service,
 		type, __connman_ipconfig_type2string(type),
 		peer, maybe_null(peer));
 
+	if (!service)
+		return -EINVAL;
+
 	index = __connman_service_get_index(service);
 
 	interface = connman_inet_ifname(index);
 
 	DBG("index %d (%s)", index, maybe_null(interface));
 
+	service_type = connman_service_get_type(service);
+
 	/*
 	 * If gateway is NULL, it's a point to point link and the default
 	 * gateway for ipv4 is 0.0.0.0 and for ipv6 is ::, meaning the