Skip to contentSkip to conversation

netfilter: nft_bitwise: Adjust parentheses to fix memcmp size argument

PATCH Applied Nathan Chancellor 4 participants 4 messages Aug 14, 2019 – Aug 15, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter: nft_bitwise: Adjust parentheses to fix memcmp size argument

clang warns:

net/netfilter/nft_bitwise.c:138:50: error: size argument in 'memcmp' call is a comparison [-Werror,-Wmemsize-comparison]

        if (memcmp(&priv->xor, &zero, sizeof(priv->xor) ||
                                      ~~~~~~~~~~~~~~~~~~^~
net/netfilter/nft_bitwise.c:138:6: note: did you mean to compare the
result of 'memcmp' instead?
        if (memcmp(&priv->xor, &zero, sizeof(priv->xor) ||
            ^
                                                       )
net/netfilter/nft_bitwise.c:138:32: note: explicitly cast the argument
to size_t to silence this warning
        if (memcmp(&priv->xor, &zero, sizeof(priv->xor) ||
                                      ^
                                      (size_t)(

1 error generated.

Adjust the parentheses so that the result of the sizeof is used for the size argument in memcmp, rather than the result of the comparison (which would always be true because sizeof is a non-zero number).

Fixes bd8699e9e292 ("netfilter: nft_bitwise: add offload support")
---
 net/netfilter/nft_bitwise.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nft_bitwise.c +2 -2
index 1f04ed5c518c..974300178fa9 100644
@@ -135,8 +135,8 @@ static int nft_bitwise_offload(struct nft_offload_ctx *ctx,
 {
 	const struct nft_bitwise *priv = nft_expr_priv(expr);
 
-	if (memcmp(&priv->xor, &zero, sizeof(priv->xor) ||
-	    priv->sreg != priv->dreg))
+	if (memcmp(&priv->xor, &zero, sizeof(priv->xor)) ||
+	    priv->sreg != priv->dreg)
 		return -EOPNOTSUPP;
 
 	memcpy(&ctx->regs[priv->dreg].mask, &priv->mask, sizeof(priv->mask));
Signature · 1 line
2.23.0.rc2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 19 lines · Nathan Chancellor

clang warns:

net/netfilter/nft_bitwise.c:138:50: error: size argument in 'memcmp' call is a comparison [-Werror,-Wmemsize-comparison]

        if (memcmp(&priv->xor, &zero, sizeof(priv->xor) ||
                                      ~~~~~~~~~~~~~~~~~~^~
net/netfilter/nft_bitwise.c:138:6: note: did you mean to compare the
result of 'memcmp' instead?
        if (memcmp(&priv->xor, &zero, sizeof(priv->xor) ||
            ^
                                                       )
net/netfilter/nft_bitwise.c:138:32: note: explicitly cast the argument
to size_t to silence this warning
        if (memcmp(&priv->xor, &zero, sizeof(priv->xor) ||
                                      ^
                                      (size_t)(

1 error generated.

Quoted 8 lines

Adjust the parentheses so that the result of the sizeof is used for the size argument in memcmp, rather than the result of the comparison (which would always be true because sizeof is a non-zero number).

Fixes bd8699e9e292 ("netfilter: nft_bitwise: add offload support")

oh no! thanks for the patch.

Quoted 22 lines
---
 net/netfilter/nft_bitwise.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nft_bitwise.c +2 -3
index 1f04ed5c518c..974300178fa9 100644
@@ -135,8 +135,8 @@ static int nft_bitwise_offload(struct nft_offload_ctx *ctx,
 {
        const struct nft_bitwise *priv = nft_expr_priv(expr);
 
-       if (memcmp(&priv->xor, &zero, sizeof(priv->xor) ||
-           priv->sreg != priv->dreg))
+       if (memcmp(&priv->xor, &zero, sizeof(priv->xor)) ||
+           priv->sreg != priv->dreg)
                return -EOPNOTSUPP;
 
        memcpy(&ctx->regs[priv->dreg].mask, &priv->mask, sizeof(priv->mask));
--

2.23.0.rc2

Signature · 2 lines
Thanks,
~Nick Desaulniers
maintainer Applied
#2 lore raw
In reply to Nathan Chancellor
Quoted 6 lines · Nathan Chancellor

clang warns:

net/netfilter/nft_bitwise.c:138:50: error: size argument in 'memcmp' call is a comparison [-Werror,-Wmemsize-comparison]

        if (memcmp(&priv->xor, &zero, sizeof(priv->xor) ||
                                      ~~~~~~~~~~~~~~~~~~^~

Applied, thanks.

#3 lore raw
In reply to Nathan Chancellor

net/netfilter/nft_bitwise.c

Quoted 31 lines · Nathan Chancellor

clang warns:

net/netfilter/nft_bitwise.c:138:50: error: size argument in 'memcmp' call is a comparison [-Werror,-Wmemsize-comparison]

        if (memcmp(&priv->xor, &zero, sizeof(priv->xor) ||
                                      ~~~~~~~~~~~~~~~~~~^~
net/netfilter/nft_bitwise.c:138:6: note: did you mean to compare the
result of 'memcmp' instead?
        if (memcmp(&priv->xor, &zero, sizeof(priv->xor) ||
            ^
                                                       )
net/netfilter/nft_bitwise.c:138:32: note: explicitly cast the argument
to size_t to silence this warning
        if (memcmp(&priv->xor, &zero, sizeof(priv->xor) ||
                                      ^
                                      (size_t)(

1 error generated.

Adjust the parentheses so that the result of the sizeof is used for the size argument in memcmp, rather than the result of the comparison (which would always be true because sizeof is a non-zero number).

Fixes bd8699e9e292 ("netfilter: nft_bitwise: add offload support")
---
 net/netfilter/nft_bitwise.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nft_bitwise.c +0 -0

[]

net/netfilter/nft_bitwise.c static int nft_bitwise_offload(struct nft_offload_ctx *ctx, · line 139

Quoted 8 lines
net/netfilter/nft_bitwise.c +2 -2
@@ -135,8 +135,8 @@ static int nft_bitwise_offload(struct nft_offload_ctx *ctx,
 {
 	const struct nft_bitwise *priv = nft_expr_priv(expr);
 
-	if (memcmp(&priv->xor, &zero, sizeof(priv->xor) ||
-	    priv->sreg != priv->dreg))
+	if (memcmp(&priv->xor, &zero, sizeof(priv->xor)) ||
+	    priv->sreg != priv->dreg)

This code should use memchr_inv and not compare against a static uninitialized struct.

Perhaps linux should introduce and use memcchr like bsd. or just add something like #define memcchr memchr_inv