[PATCH] connman : Add null check in prepare_target to avoid SIG=6

Shailesh Rathod/LGSI GPOS Dev <[email protected]> Mon, 2 Jun 2025 06:49:36 +0000
Newsgroups dev.linux.lists.connman
Message-ID <SE1P216MB264701D18124CD7147BCAF1AF062A@SE1P216MB2647.KORP216.PROD.OUTLOOK.COM>
From: Shailesh Rathod <[email protected]>
Date: Wed, 23 Apr 2025 17:48:14 +0900

Add null check in prepare_target to avoid SIG=6

When Ethernet is connected and an attempt is made to enable the SoftAP,
a SIGSEGV (signal 6) is observed.To prevent this, add a null check to
avoid the segmentation fault.

Signed-off-by: Shailesh Rathod<[email protected]>
---
 src/iptables.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/iptables.c b/src/iptables.c
index a81a077..54e04d3 100644
--- a/src/iptables.c
+++ b/src/iptables.c
@@ -2746,20 +2746,21 @@ static struct xtables_target *prepare_target(struct connman_iptables *table,

    switch (table->type) {
    case AF_INET:
-       if (xt_t->x6_options)
+       if (xt_t->x6_options && xt_t->option_offset){
            iptables_globals.opts =
                xtables_options_xfrm(
                    iptables_globals.orig_opts,
                    iptables_globals.opts,
                    xt_t->x6_options,
                    &xt_t->option_offset);
-       else
+       }else if(xt_t->extra_opts && xt_t->option_offset){
            iptables_globals.opts =
                xtables_merge_options(
                    iptables_globals.orig_opts,
                    iptables_globals.opts,
                    xt_t->extra_opts,
                    &xt_t->option_offset);
+       }

        if (!iptables_globals.opts) {
            g_free(xt_t->t);
@@ -2768,21 +2769,21 @@ static struct xtables_target *prepare_target(struct connman_iptables *table,

        break;
    case AF_INET6:
-       if (xt_t->x6_options)
+       if (xt_t->x6_options && xt_t->option_offset){
            ip6tables_globals.opts =
                xtables_options_xfrm(
                    ip6tables_globals.orig_opts,
                    ip6tables_globals.opts,
                    xt_t->x6_options,
                    &xt_t->option_offset);
-       else
+       }else if(xt_t->extra_opts && xt_t->option_offset){
            ip6tables_globals.opts =
                xtables_merge_options(
                    ip6tables_globals.orig_opts,
                    ip6tables_globals.opts,
                    xt_t->extra_opts,
                    &xt_t->option_offset);
-
+       }
        if (!ip6tables_globals.opts) {
            g_free(xt_t->t);
            xt_t = NULL;