Commit 6d87a4ea authored by Justin Stitt's avatar Justin Stitt Committed by Florian Westphal

netfilter: nft_osf: refactor deprecated strncpy

Use `strscpy_pad` over `strncpy` for NUL-terminated strings.

We can also drop the + 1 from `NFT_OSF_MAXGENRELEN + 1` since `strscpy`
will guarantee NUL-termination.
Signed-off-by: default avatarJustin Stitt <justinstitt@google.com>
Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
parent 7457af8b
...@@ -23,7 +23,7 @@ static void nft_osf_eval(const struct nft_expr *expr, struct nft_regs *regs, ...@@ -23,7 +23,7 @@ static void nft_osf_eval(const struct nft_expr *expr, struct nft_regs *regs,
struct nft_osf *priv = nft_expr_priv(expr); struct nft_osf *priv = nft_expr_priv(expr);
u32 *dest = &regs->data[priv->dreg]; u32 *dest = &regs->data[priv->dreg];
struct sk_buff *skb = pkt->skb; struct sk_buff *skb = pkt->skb;
char os_match[NFT_OSF_MAXGENRELEN + 1]; char os_match[NFT_OSF_MAXGENRELEN];
const struct tcphdr *tcp; const struct tcphdr *tcp;
struct nf_osf_data data; struct nf_osf_data data;
struct tcphdr _tcph; struct tcphdr _tcph;
...@@ -45,7 +45,7 @@ static void nft_osf_eval(const struct nft_expr *expr, struct nft_regs *regs, ...@@ -45,7 +45,7 @@ static void nft_osf_eval(const struct nft_expr *expr, struct nft_regs *regs,
} }
if (!nf_osf_find(skb, nf_osf_fingers, priv->ttl, &data)) { if (!nf_osf_find(skb, nf_osf_fingers, priv->ttl, &data)) {
strncpy((char *)dest, "unknown", NFT_OSF_MAXGENRELEN); strscpy_pad((char *)dest, "unknown", NFT_OSF_MAXGENRELEN);
} else { } else {
if (priv->flags & NFT_OSF_F_VERSION) if (priv->flags & NFT_OSF_F_VERSION)
snprintf(os_match, NFT_OSF_MAXGENRELEN, "%s:%s", snprintf(os_match, NFT_OSF_MAXGENRELEN, "%s:%s",
...@@ -53,7 +53,7 @@ static void nft_osf_eval(const struct nft_expr *expr, struct nft_regs *regs, ...@@ -53,7 +53,7 @@ static void nft_osf_eval(const struct nft_expr *expr, struct nft_regs *regs,
else else
strscpy(os_match, data.genre, NFT_OSF_MAXGENRELEN); strscpy(os_match, data.genre, NFT_OSF_MAXGENRELEN);
strncpy((char *)dest, os_match, NFT_OSF_MAXGENRELEN); strscpy_pad((char *)dest, os_match, NFT_OSF_MAXGENRELEN);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment