netfilter: move from strlcpy with unused retval to strscpy
authorWolfram Sang <wsa+renesas@sang-engineering.com>
Thu, 18 Aug 2022 21:02:24 +0000 (23:02 +0200)
committerFlorian Westphal <fw@strlen.de>
Wed, 7 Sep 2022 14:46:03 +0000 (16:46 +0200)
Follow the advice of the below link and prefer 'strscpy' in this
subsystem. Conversion is 1:1 because the return value is not used.
Generated by a coccinelle script.

Link: https://lore.kernel.org/r/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw@mail.gmail.com/
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Simon Horman <horms@verge.net.au>
Signed-off-by: Florian Westphal <fw@strlen.de>
net/netfilter/ipset/ip_set_core.c
net/netfilter/ipvs/ip_vs_ctl.c
net/netfilter/nf_log.c
net/netfilter/nf_tables_api.c
net/netfilter/nft_osf.c
net/netfilter/x_tables.c
net/netfilter/xt_RATEEST.c

index 6b31746f9be3b158da1ae611aeecf6e942e33578..e7ba5b6dd2b7c1792e76723f68553f8d174e1ae9 100644 (file)
@@ -353,7 +353,7 @@ ip_set_init_comment(struct ip_set *set, struct ip_set_comment *comment,
        c = kmalloc(sizeof(*c) + len + 1, GFP_ATOMIC);
        if (unlikely(!c))
                return;
-       strlcpy(c->str, ext->comment, len + 1);
+       strscpy(c->str, ext->comment, len + 1);
        set->ext_size += sizeof(*c) + strlen(c->str) + 1;
        rcu_assign_pointer(comment->c, c);
 }
@@ -1072,7 +1072,7 @@ static int ip_set_create(struct sk_buff *skb, const struct nfnl_info *info,
        if (!set)
                return -ENOMEM;
        spin_lock_init(&set->lock);
-       strlcpy(set->name, name, IPSET_MAXNAMELEN);
+       strscpy(set->name, name, IPSET_MAXNAMELEN);
        set->family = family;
        set->revision = revision;
 
index 818b0b058b10c06e634610e67faff65ac4583d7f..988222fff9f025a6635b66e47ad518e67e34c182 100644 (file)
@@ -2611,7 +2611,7 @@ ip_vs_copy_service(struct ip_vs_service_entry *dst, struct ip_vs_service *src)
        dst->addr = src->addr.ip;
        dst->port = src->port;
        dst->fwmark = src->fwmark;
-       strlcpy(dst->sched_name, sched_name, sizeof(dst->sched_name));
+       strscpy(dst->sched_name, sched_name, sizeof(dst->sched_name));
        dst->flags = src->flags;
        dst->timeout = src->timeout / HZ;
        dst->netmask = src->netmask;
@@ -2805,13 +2805,13 @@ do_ip_vs_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
                mutex_lock(&ipvs->sync_mutex);
                if (ipvs->sync_state & IP_VS_STATE_MASTER) {
                        d[0].state = IP_VS_STATE_MASTER;
-                       strlcpy(d[0].mcast_ifn, ipvs->mcfg.mcast_ifn,
+                       strscpy(d[0].mcast_ifn, ipvs->mcfg.mcast_ifn,
                                sizeof(d[0].mcast_ifn));
                        d[0].syncid = ipvs->mcfg.syncid;
                }
                if (ipvs->sync_state & IP_VS_STATE_BACKUP) {
                        d[1].state = IP_VS_STATE_BACKUP;
-                       strlcpy(d[1].mcast_ifn, ipvs->bcfg.mcast_ifn,
+                       strscpy(d[1].mcast_ifn, ipvs->bcfg.mcast_ifn,
                                sizeof(d[1].mcast_ifn));
                        d[1].syncid = ipvs->bcfg.syncid;
                }
@@ -3561,7 +3561,7 @@ static int ip_vs_genl_new_daemon(struct netns_ipvs *ipvs, struct nlattr **attrs)
              attrs[IPVS_DAEMON_ATTR_MCAST_IFN] &&
              attrs[IPVS_DAEMON_ATTR_SYNC_ID]))
                return -EINVAL;
-       strlcpy(c.mcast_ifn, nla_data(attrs[IPVS_DAEMON_ATTR_MCAST_IFN]),
+       strscpy(c.mcast_ifn, nla_data(attrs[IPVS_DAEMON_ATTR_MCAST_IFN]),
                sizeof(c.mcast_ifn));
        c.syncid = nla_get_u32(attrs[IPVS_DAEMON_ATTR_SYNC_ID]);
 
index edee7fa944c13a07c19bf7ddce84b908fe0c6836..8a29290149bd789a424012a4a1c6f161ea7be327 100644 (file)
@@ -443,9 +443,9 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
                mutex_lock(&nf_log_mutex);
                logger = nft_log_dereference(net->nf.nf_loggers[tindex]);
                if (!logger)
-                       strlcpy(buf, "NONE", sizeof(buf));
+                       strscpy(buf, "NONE", sizeof(buf));
                else
-                       strlcpy(buf, logger->name, sizeof(buf));
+                       strscpy(buf, logger->name, sizeof(buf));
                mutex_unlock(&nf_log_mutex);
                r = proc_dostring(&tmp, write, buffer, lenp, ppos);
        }
index 2ee50e23c9b716986fde758d6d821cfded021a01..12406006852d42e92d4b5a50e9d0e57d47dcc19e 100644 (file)
@@ -742,7 +742,7 @@ __printf(2, 3) int nft_request_module(struct net *net, const char *fmt,
                return -ENOMEM;
 
        req->done = false;
-       strlcpy(req->module, module_name, MODULE_NAME_LEN);
+       strscpy(req->module, module_name, MODULE_NAME_LEN);
        list_add_tail(&req->list, &nft_net->module_list);
 
        return -EAGAIN;
index 89342ccccdccf6a333155e9b841826ff0b4ce7c0..adacf95b6e2bd204ea50c689f38be37642daaa18 100644 (file)
@@ -51,7 +51,7 @@ static void nft_osf_eval(const struct nft_expr *expr, struct nft_regs *regs,
                        snprintf(os_match, NFT_OSF_MAXGENRELEN, "%s:%s",
                                 data.genre, data.version);
                else
-                       strlcpy(os_match, data.genre, NFT_OSF_MAXGENRELEN);
+                       strscpy(os_match, data.genre, NFT_OSF_MAXGENRELEN);
 
                strncpy((char *)dest, os_match, NFT_OSF_MAXGENRELEN);
        }
index 54a489f16b171220aaffef3ea43355fd89cd91ce..470282cf3fae61884894765965105c96537dc3a2 100644 (file)
@@ -766,7 +766,7 @@ void xt_compat_match_from_user(struct xt_entry_match *m, void **dstptr,
 
        msize += off;
        m->u.user.match_size = msize;
-       strlcpy(name, match->name, sizeof(name));
+       strscpy(name, match->name, sizeof(name));
        module_put(match->me);
        strncpy(m->u.user.name, name, sizeof(m->u.user.name));
 
@@ -1146,7 +1146,7 @@ void xt_compat_target_from_user(struct xt_entry_target *t, void **dstptr,
 
        tsize += off;
        t->u.user.target_size = tsize;
-       strlcpy(name, target->name, sizeof(name));
+       strscpy(name, target->name, sizeof(name));
        module_put(target->me);
        strncpy(t->u.user.name, name, sizeof(t->u.user.name));
 
@@ -1827,7 +1827,7 @@ int xt_proto_init(struct net *net, u_int8_t af)
        root_uid = make_kuid(net->user_ns, 0);
        root_gid = make_kgid(net->user_ns, 0);
 
-       strlcpy(buf, xt_prefix[af], sizeof(buf));
+       strscpy(buf, xt_prefix[af], sizeof(buf));
        strlcat(buf, FORMAT_TABLES, sizeof(buf));
        proc = proc_create_net_data(buf, 0440, net->proc_net, &xt_table_seq_ops,
                        sizeof(struct seq_net_private),
@@ -1837,7 +1837,7 @@ int xt_proto_init(struct net *net, u_int8_t af)
        if (uid_valid(root_uid) && gid_valid(root_gid))
                proc_set_user(proc, root_uid, root_gid);
 
-       strlcpy(buf, xt_prefix[af], sizeof(buf));
+       strscpy(buf, xt_prefix[af], sizeof(buf));
        strlcat(buf, FORMAT_MATCHES, sizeof(buf));
        proc = proc_create_seq_private(buf, 0440, net->proc_net,
                        &xt_match_seq_ops, sizeof(struct nf_mttg_trav),
@@ -1847,7 +1847,7 @@ int xt_proto_init(struct net *net, u_int8_t af)
        if (uid_valid(root_uid) && gid_valid(root_gid))
                proc_set_user(proc, root_uid, root_gid);
 
-       strlcpy(buf, xt_prefix[af], sizeof(buf));
+       strscpy(buf, xt_prefix[af], sizeof(buf));
        strlcat(buf, FORMAT_TARGETS, sizeof(buf));
        proc = proc_create_seq_private(buf, 0440, net->proc_net,
                         &xt_target_seq_ops, sizeof(struct nf_mttg_trav),
@@ -1862,12 +1862,12 @@ int xt_proto_init(struct net *net, u_int8_t af)
 
 #ifdef CONFIG_PROC_FS
 out_remove_matches:
-       strlcpy(buf, xt_prefix[af], sizeof(buf));
+       strscpy(buf, xt_prefix[af], sizeof(buf));
        strlcat(buf, FORMAT_MATCHES, sizeof(buf));
        remove_proc_entry(buf, net->proc_net);
 
 out_remove_tables:
-       strlcpy(buf, xt_prefix[af], sizeof(buf));
+       strscpy(buf, xt_prefix[af], sizeof(buf));
        strlcat(buf, FORMAT_TABLES, sizeof(buf));
        remove_proc_entry(buf, net->proc_net);
 out:
@@ -1881,15 +1881,15 @@ void xt_proto_fini(struct net *net, u_int8_t af)
 #ifdef CONFIG_PROC_FS
        char buf[XT_FUNCTION_MAXNAMELEN];
 
-       strlcpy(buf, xt_prefix[af], sizeof(buf));
+       strscpy(buf, xt_prefix[af], sizeof(buf));
        strlcat(buf, FORMAT_TABLES, sizeof(buf));
        remove_proc_entry(buf, net->proc_net);
 
-       strlcpy(buf, xt_prefix[af], sizeof(buf));
+       strscpy(buf, xt_prefix[af], sizeof(buf));
        strlcat(buf, FORMAT_TARGETS, sizeof(buf));
        remove_proc_entry(buf, net->proc_net);
 
-       strlcpy(buf, xt_prefix[af], sizeof(buf));
+       strscpy(buf, xt_prefix[af], sizeof(buf));
        strlcat(buf, FORMAT_MATCHES, sizeof(buf));
        remove_proc_entry(buf, net->proc_net);
 #endif /*CONFIG_PROC_FS*/
index 8aec1b529364ae1702f38a1ce4dd69c79cd6eb5e..80f6624e23554b30090b4a86b763ad279f5e44ac 100644 (file)
@@ -144,7 +144,7 @@ static int xt_rateest_tg_checkentry(const struct xt_tgchk_param *par)
                goto err1;
 
        gnet_stats_basic_sync_init(&est->bstats);
-       strlcpy(est->name, info->name, sizeof(est->name));
+       strscpy(est->name, info->name, sizeof(est->name));
        spin_lock_init(&est->lock);
        est->refcnt             = 1;
        est->params.interval    = info->interval;