netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [nft]: fix some bugs of return value
@ 2015-11-24  9:00 Linmujia
  2015-11-25 13:03 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 2+ messages in thread
From: Linmujia @ 2015-11-24  9:00 UTC (permalink / raw)
  To: netfilter-devel@vger.kernel.org; +Cc: pablo@netfilter.org

[-- Attachment #1: Type: text/plain, Size: 2322 bytes --]


linmujia - Nov. 24, 2015, 04:03 p.m.

Signed-off-by: linmujia <linmujia@huawei.com>
---
hello ,i reviewed nftables code and found some bugs of return value.

Thanks!



Patch

diff --git a/src/netlink.c b/src/netlink.c
index 974afb1..c555621 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -307,6 +307,8 @@ static void netlink_gen_verdict(const struct expr *expr,
 		strncpy(data->chain, expr->chain, NFT_CHAIN_MAXNAMELEN);
 		data->chain[NFT_CHAIN_MAXNAMELEN-1] = '\0';
 		break;
+	default:
+		BUG("invalid verdict value %u\n", expr->verdict);
 	}
 }
 
@@ -467,7 +469,7 @@ static int list_rule_cb(struct nftnl_rule *nlr, void *arg)
 	if (h->family != family ||
 	    strcmp(table, h->table) != 0 ||
 	    (h->chain && strcmp(chain, h->chain) != 0))
-		return 0;
+		return -1;
 
 	netlink_dump_rule(nlr);
 	rule = netlink_delinearize_rule(ctx, nlr);
diff --git a/src/rule.c b/src/rule.c
index 5d3cd84..9d6d945 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -930,7 +930,7 @@ static int do_command_add(struct netlink_ctx *ctx, struct cmd *cmd, bool excl)
 	default:
 		BUG("invalid command object type %u\n", cmd->obj);
 	}
-	return 0;
+	return -1;
 }
 
 static int do_command_replace(struct netlink_ctx *ctx, struct cmd *cmd)
@@ -942,7 +942,7 @@ static int do_command_replace(struct netlink_ctx *ctx, struct cmd *cmd)
 	default:
 		BUG("invalid command object type %u\n", cmd->obj);
 	}
-	return 0;
+	return -1;
 }
 
 static int do_command_insert(struct netlink_ctx *ctx, struct cmd *cmd)
@@ -954,7 +954,7 @@ static int do_command_insert(struct netlink_ctx *ctx, struct cmd *cmd)
 	default:
 		BUG("invalid command object type %u\n", cmd->obj);
 	}
-	return 0;
+	return -1;
 }
 
 static int do_command_delete(struct netlink_ctx *ctx, struct cmd *cmd)
@@ -974,6 +974,7 @@ static int do_command_delete(struct netlink_ctx *ctx, struct cmd *cmd)
 	default:
 		BUG("invalid command object type %u\n", cmd->obj);
 	}
+    return -1;
 }
 
 static int do_command_export(struct netlink_ctx *ctx, struct cmd *cmd)
@@ -1258,6 +1259,7 @@ int do_command(struct netlink_ctx *ctx, struct cmd *cmd)
 	default:
 		BUG("invalid command object type %u\n", cmd->obj);
 	}
+	return -1;
 }
 
 static int payload_match_stmt_cmp(const void *p1, const void *p2)



[-- Attachment #2: p001.patch --]
[-- Type: application/octet-stream, Size: 2059 bytes --]

diff --git a/src/netlink.c b/src/netlink.c
index 974afb1..c555621 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -307,6 +307,8 @@ static void netlink_gen_verdict(const struct expr *expr,
 		strncpy(data->chain, expr->chain, NFT_CHAIN_MAXNAMELEN);
 		data->chain[NFT_CHAIN_MAXNAMELEN-1] = '\0';
 		break;
+	default:
+		BUG("invalid verdict value %u\n", expr->verdict);
 	}
 }
 
@@ -467,7 +469,7 @@ static int list_rule_cb(struct nftnl_rule *nlr, void *arg)
 	if (h->family != family ||
 	    strcmp(table, h->table) != 0 ||
 	    (h->chain && strcmp(chain, h->chain) != 0))
-		return 0;
+		return -1;
 
 	netlink_dump_rule(nlr);
 	rule = netlink_delinearize_rule(ctx, nlr);
diff --git a/src/rule.c b/src/rule.c
index 5d3cd84..9d6d945 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -930,7 +930,7 @@ static int do_command_add(struct netlink_ctx *ctx, struct cmd *cmd, bool excl)
 	default:
 		BUG("invalid command object type %u\n", cmd->obj);
 	}
-	return 0;
+	return -1;
 }
 
 static int do_command_replace(struct netlink_ctx *ctx, struct cmd *cmd)
@@ -942,7 +942,7 @@ static int do_command_replace(struct netlink_ctx *ctx, struct cmd *cmd)
 	default:
 		BUG("invalid command object type %u\n", cmd->obj);
 	}
-	return 0;
+	return -1;
 }
 
 static int do_command_insert(struct netlink_ctx *ctx, struct cmd *cmd)
@@ -954,7 +954,7 @@ static int do_command_insert(struct netlink_ctx *ctx, struct cmd *cmd)
 	default:
 		BUG("invalid command object type %u\n", cmd->obj);
 	}
-	return 0;
+	return -1;
 }
 
 static int do_command_delete(struct netlink_ctx *ctx, struct cmd *cmd)
@@ -974,6 +974,7 @@ static int do_command_delete(struct netlink_ctx *ctx, struct cmd *cmd)
 	default:
 		BUG("invalid command object type %u\n", cmd->obj);
 	}
+    return -1;
 }
 
 static int do_command_export(struct netlink_ctx *ctx, struct cmd *cmd)
@@ -1258,6 +1259,7 @@ int do_command(struct netlink_ctx *ctx, struct cmd *cmd)
 	default:
 		BUG("invalid command object type %u\n", cmd->obj);
 	}
+	return -1;
 }
 
 static int payload_match_stmt_cmp(const void *p1, const void *p2)

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-11-25 13:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-24  9:00 [nft]: fix some bugs of return value Linmujia
2015-11-25 13:03 ` Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).