wispr: Prevent use-after-free from __connman_wispr_stop() 63/275463/2 accepted/tizen/unified/20220530.140608 submit/tizen/20220527.121228
authorSeung-Woo Kim <sw0312.kim@samsung.com>
Tue, 24 May 2022 09:59:21 +0000 (18:59 +0900)
committerJaehyun Kim <jeik01.kim@samsung.com>
Fri, 27 May 2022 07:57:18 +0000 (07:57 +0000)
From __connman_wispr_stop(), list element wispr_portal freed by
g_hash_table_remove() is accessed. Prevent the use-after-free by
accessing the list element before free.

Change-Id: I17fdb38c1d9a0f8dd2980c33d3f78f319f504ed6

src/wispr.c

index fb101a1..4674ae4 100755 (executable)
@@ -1047,17 +1047,11 @@ void __connman_wispr_stop(struct connman_service *service)
        if (!wispr_portal)
                return;
 
-       if (wispr_portal->ipv4_context) {
-               if (service == wispr_portal->ipv4_context->service)
-                       g_hash_table_remove(wispr_portal_list,
-                                       GINT_TO_POINTER(index));
-       }
-
-       if (wispr_portal->ipv6_context) {
-               if (service == wispr_portal->ipv6_context->service)
-                       g_hash_table_remove(wispr_portal_list,
-                                       GINT_TO_POINTER(index));
-       }
+       if ((wispr_portal->ipv4_context &&
+            service == wispr_portal->ipv4_context->service) ||
+           (wispr_portal->ipv6_context &&
+            service == wispr_portal->ipv6_context->service))
+               g_hash_table_remove(wispr_portal_list, GINT_TO_POINTER(index));
 }
 
 int __connman_wispr_init(void)