Skip to content

Commit 4e09fc8

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: prefer nla_strlcpy for dealing with NLA_STRING attributes
fixes these warnings: 'nfnl_cthelper_create' at net/netfilter/nfnetlink_cthelper.c:237:2, 'nfnl_cthelper_new' at net/netfilter/nfnetlink_cthelper.c:450:9: ./include/linux/string.h:246:9: warning: '__builtin_strncpy' specified bound 16 equals destination size [-Wstringop-truncation] return __builtin_strncpy(p, q, size); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Moreover, strncpy assumes null-terminated source buffers, but thats not the case here. Unlike strlcpy, nla_strlcpy *does* pad the destination buffer while also considering nla attribute size. Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 25fd386 commit 4e09fc8

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

net/netfilter/nfnetlink_acct.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static int nfnl_acct_new(struct net *net, struct sock *nfnl,
115115
nfacct->flags = flags;
116116
}
117117

118-
strncpy(nfacct->name, nla_data(tb[NFACCT_NAME]), NFACCT_NAME_MAX);
118+
nla_strlcpy(nfacct->name, nla_data(tb[NFACCT_NAME]), NFACCT_NAME_MAX);
119119

120120
if (tb[NFACCT_BYTES]) {
121121
atomic64_set(&nfacct->bytes,

net/netfilter/nfnetlink_cthelper.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ nfnl_cthelper_expect_policy(struct nf_conntrack_expect_policy *expect_policy,
149149
!tb[NFCTH_POLICY_EXPECT_TIMEOUT])
150150
return -EINVAL;
151151

152-
strncpy(expect_policy->name,
153-
nla_data(tb[NFCTH_POLICY_NAME]), NF_CT_HELPER_NAME_LEN);
152+
nla_strlcpy(expect_policy->name,
153+
nla_data(tb[NFCTH_POLICY_NAME]), NF_CT_HELPER_NAME_LEN);
154154
expect_policy->max_expected =
155155
ntohl(nla_get_be32(tb[NFCTH_POLICY_EXPECT_MAX]));
156156
if (expect_policy->max_expected > NF_CT_EXPECT_MAX_CNT)
@@ -234,7 +234,8 @@ nfnl_cthelper_create(const struct nlattr * const tb[],
234234
if (ret < 0)
235235
goto err1;
236236

237-
strncpy(helper->name, nla_data(tb[NFCTH_NAME]), NF_CT_HELPER_NAME_LEN);
237+
nla_strlcpy(helper->name,
238+
nla_data(tb[NFCTH_NAME]), NF_CT_HELPER_NAME_LEN);
238239
size = ntohl(nla_get_be32(tb[NFCTH_PRIV_DATA_LEN]));
239240
if (size > FIELD_SIZEOF(struct nf_conn_help, data)) {
240241
ret = -ENOMEM;

0 commit comments

Comments
 (0)