wisrp: Handle wispr_portal_detect failures
PATCH 1/1 wisrp: Handle wispr_portal_detect failures
__connman_wispr_start() should handle any errors reported by wispr_portal_detect.
While at it also return early if the service type is not supported.
--- src/wispr.c | 56 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 24 deletions(-)
src/wispr.c +32 -24
@@ -916,7 +916,6 @@ static gboolean no_proxy_callback(gpointer user_data)static int wispr_portal_detect (struct connman_wispr_portal_context *wp_context) {enum connman_service_proxy_method proxy_method; -enum connman_service_type service_type;char *interface =NULL ;char **nameservers =NULL ;int if_index;
@@ -926,23 +925,6 @@ static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)DBG ("wispr/portal context %p service %p" , wp_context, wp_context->service); - service_type =connman_service_get_type (wp_context->service); - -switch (service_type) { -case CONNMAN_SERVICE_TYPE_ETHERNET : -case CONNMAN_SERVICE_TYPE_WIFI : -case CONNMAN_SERVICE_TYPE_BLUETOOTH : -case CONNMAN_SERVICE_TYPE_CELLULAR : -case CONNMAN_SERVICE_TYPE_GADGET : -break ; -case CONNMAN_SERVICE_TYPE_UNKNOWN : -case CONNMAN_SERVICE_TYPE_SYSTEM : -case CONNMAN_SERVICE_TYPE_GPS : -case CONNMAN_SERVICE_TYPE_VPN : -case CONNMAN_SERVICE_TYPE_P2P : -return -EOPNOTSUPP ; - } - interface =connman_service_get_interface (wp_context->service);if (!interface)return -EINVAL ;
@@ -1012,13 +994,28 @@ int __connman_wispr_start(struct connman_service *service, {struct connman_wispr_portal_context *wp_context =NULL ;struct connman_wispr_portal *wispr_portal =NULL ; -int index; +int index, err;DBG ("service %p" , service);if (!wispr_portal_hash)return -EINVAL ; +switch (connman_service_get_type (service)) { +case CONNMAN_SERVICE_TYPE_ETHERNET : +case CONNMAN_SERVICE_TYPE_WIFI : +case CONNMAN_SERVICE_TYPE_BLUETOOTH : +case CONNMAN_SERVICE_TYPE_CELLULAR : +case CONNMAN_SERVICE_TYPE_GADGET : +break ; +case CONNMAN_SERVICE_TYPE_UNKNOWN : +case CONNMAN_SERVICE_TYPE_SYSTEM : +case CONNMAN_SERVICE_TYPE_GPS : +case CONNMAN_SERVICE_TYPE_VPN : +case CONNMAN_SERVICE_TYPE_P2P : +return -EOPNOTSUPP ; + } + index =__connman_service_get_index (service);if (index <0 )return -EINVAL ;
@@ -1038,16 +1035,20 @@ int __connman_wispr_start(struct connman_service *service, wp_context = wispr_portal->ipv4_context; else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) wp_context = wispr_portal->ipv6_context; - else - return -EINVAL; + else { + err = -EINVAL ; + goto free_wp; + }/* If there is already an existing context, we wipe it */ if (wp_context)wispr_portal_context_unref (wp_context); wp_context =create_wispr_portal_context (); -if (!wp_context) -return -ENOMEM ; +if (!wp_context) { + err = -ENOMEM ; + goto free_wp; + } wp_context->service = service; wp_context->type = type;
@@ -1058,7 +1059,14 @@ int __connman_wispr_start(struct connman_service *service,else wispr_portal->ipv6_context = wp_context; -return wispr_portal_detect (wp_context); + err =wispr_portal_detect (wp_context); +if (err) + goto free_wp; +return 0 ; + +free_wp: +g_hash_table_remove (wispr_portal_hash,GINT_TO_POINTER (index)); +return err; }void __connman_wispr_stop (struct connman_service *service)
Signature · 1 line
2.37.2
Daniel Wagner
AppliedQuoted 4 lines · Daniel Wagner
__connman_wispr_start()should handle any errors reported bywispr_portal_detect.While at it also return early if the service type is not supported.
applied