Skip to content

Commit

Permalink
netfilter: nft_lookup: use nft_validate_register_store() to validate …
Browse files Browse the repository at this point in the history
…types

In preparation of validating the length of a register store, use
nft_validate_register_store() in nft_lookup instead of open coding the
validation.

Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
  • Loading branch information
kaber authored and ummakynes committed Apr 13, 2015
1 parent 1ec1021 commit 58f40ab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
7 changes: 4 additions & 3 deletions net/netfilter/nf_tables_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -4169,7 +4169,7 @@ EXPORT_SYMBOL_GPL(nft_validate_output_register);
* Validate that a data load uses the appropriate data type for
* the destination register and the length is within the bounds.
* A value of NULL for the data means that its runtime gathered
* data, which is always of type NFT_DATA_VALUE.
* data.
*/
int nft_validate_register_store(const struct nft_ctx *ctx,
enum nft_registers reg,
Expand All @@ -4180,10 +4180,11 @@ int nft_validate_register_store(const struct nft_ctx *ctx,

switch (reg) {
case NFT_REG_VERDICT:
if (data == NULL || type != NFT_DATA_VERDICT)
if (type != NFT_DATA_VERDICT)
return -EINVAL;

if (data->verdict == NFT_GOTO || data->verdict == NFT_JUMP) {
if (data != NULL &&
(data->verdict == NFT_GOTO || data->verdict == NFT_JUMP)) {
err = nf_tables_check_loops(ctx, data->chain);
if (err < 0)
return err;
Expand Down
9 changes: 4 additions & 5 deletions net/netfilter/nft_lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,10 @@ static int nft_lookup_init(const struct nft_ctx *ctx,
if (err < 0)
return err;

if (priv->dreg == NFT_REG_VERDICT) {
if (set->dtype != NFT_DATA_VERDICT)
return -EINVAL;
} else if (set->dtype == NFT_DATA_VERDICT)
return -EINVAL;
err = nft_validate_register_store(ctx, priv->dreg, NULL,
set->dtype, set->dlen);
if (err < 0)
return err;
} else if (set->flags & NFT_SET_MAP)
return -EINVAL;

Expand Down

0 comments on commit 58f40ab

Please sign in to comment.