[PATCH v2 nft] libnftables: Print error and exit for empty string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



For e.g.

nft -c "  "
nft: no command specified

Without this patch it segfaults.

Signed-off-by: Harsha Sharma <harshasharmaiitr@xxxxxxxxx>
---
Changes in v2:
 - Return when state->cmds is an empty list
 - Change log message and subject

 src/libnftables.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/libnftables.c b/src/libnftables.c
index c86d894..1406dae 100644
--- a/src/libnftables.c
+++ b/src/libnftables.c
@@ -33,6 +33,11 @@ static int nft_netlink(struct nft_ctx *nft,
 	batch = mnl_batch_init();
 
 	batch_seqnum = mnl_batch_begin(batch, mnl_seqnum_alloc(&seqnum));
+
+	if (list_empty(&state->cmds)) {
+		fprintf(stderr, "nft: no command specified\n");
+		goto out;
+	}
 	list_for_each_entry(cmd, &state->cmds, list) {
 		memset(&ctx, 0, sizeof(ctx));
 		ctx.msgs = msgs;
-- 
2.14.1

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux