All of lore.kernel.org
 help / color / mirror / Atom feed
* [libnftnl PATCH 0/6] Another round of Covscan indicated fixes
@ 2017-12-14 19:40 Phil Sutter
  2017-12-14 19:40 ` [libnftnl PATCH 1/6] nftnl_data_reg_snprintf: Add a missing break Phil Sutter
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: Phil Sutter @ 2017-12-14 19:40 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

This series fixes potential issues identified by a recent Covscan run.

Phil Sutter (6):
  nftnl_data_reg_snprintf: Add a missing break
  src/gen: Remove a pointless call to mnl_nlmsg_get_payload()
  src/object: Avoid returning garbage in nftnl_obj_do_parse()
  src/ruleset: Avoid reading garbage in nftnl_ruleset_cb()
  src/set_elem: Don't return garbage in nftnl_set_elems_parse()
  src/trace: Check return value of mnl_attr_parse_nested()

 src/expr/data_reg.c |  1 +
 src/gen.c           |  4 ++--
 src/object.c        |  2 +-
 src/ruleset.c       | 10 +++++-----
 src/set_elem.c      |  2 +-
 src/trace.c         |  3 ++-
 6 files changed, 12 insertions(+), 10 deletions(-)

-- 
2.13.1


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

* [libnftnl PATCH 1/6] nftnl_data_reg_snprintf: Add a missing break
  2017-12-14 19:40 [libnftnl PATCH 0/6] Another round of Covscan indicated fixes Phil Sutter
@ 2017-12-14 19:40 ` Phil Sutter
  2017-12-15 15:17   ` Pablo Neira Ayuso
  2017-12-14 19:40 ` [libnftnl PATCH 2/6] src/gen: Remove a pointless call to mnl_nlmsg_get_payload() Phil Sutter
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Phil Sutter @ 2017-12-14 19:40 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

The code works fine as-is, but if reg_type == DATA_VALUE &&
output_format == NFTNL_OUTPUT_XML, we fall through to DATA_CHAIN case
and therefore pointlessly check output_format again.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 src/expr/data_reg.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/expr/data_reg.c b/src/expr/data_reg.c
index a246952f7f01b..c087d792a8af6 100644
--- a/src/expr/data_reg.c
+++ b/src/expr/data_reg.c
@@ -207,6 +207,7 @@ int nftnl_data_reg_snprintf(char *buf, size_t size,
 		default:
 			break;
 		}
+		break;
 	case DATA_VERDICT:
 	case DATA_CHAIN:
 		switch(output_format) {
-- 
2.13.1


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

* [libnftnl PATCH 2/6] src/gen: Remove a pointless call to mnl_nlmsg_get_payload()
  2017-12-14 19:40 [libnftnl PATCH 0/6] Another round of Covscan indicated fixes Phil Sutter
  2017-12-14 19:40 ` [libnftnl PATCH 1/6] nftnl_data_reg_snprintf: Add a missing break Phil Sutter
@ 2017-12-14 19:40 ` Phil Sutter
  2017-12-15 15:17   ` Pablo Neira Ayuso
  2017-12-14 19:40 ` [libnftnl PATCH 3/6] src/object: Avoid returning garbage in nftnl_obj_do_parse() Phil Sutter
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Phil Sutter @ 2017-12-14 19:40 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

It is a common idiom in all *_nlmsg_parse() functions, but
nftnl_gen_nlmsg_parse() doesn't make use of the data pointer and the
compiler probably can't eliminate it since there could be a side-effect.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 src/gen.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/gen.c b/src/gen.c
index 58b3a96dbdcb9..eafb015a25345 100644
--- a/src/gen.c
+++ b/src/gen.c
@@ -143,9 +143,9 @@ static int nftnl_gen_parse_attr_cb(const struct nlattr *attr, void *data)
 int nftnl_gen_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_gen *gen)
 {
 	struct nlattr *tb[NFTA_GEN_MAX + 1] = {};
-	struct nfgenmsg *nfg = mnl_nlmsg_get_payload(nlh);
 
-	if (mnl_attr_parse(nlh, sizeof(*nfg), nftnl_gen_parse_attr_cb, tb) < 0)
+	if (mnl_attr_parse(nlh, sizeof(struct nfgenmsg),
+			   nftnl_gen_parse_attr_cb, tb) < 0)
 		return -1;
 
 	if (tb[NFTA_GEN_ID]) {
-- 
2.13.1


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

* [libnftnl PATCH 3/6] src/object: Avoid returning garbage in nftnl_obj_do_parse()
  2017-12-14 19:40 [libnftnl PATCH 0/6] Another round of Covscan indicated fixes Phil Sutter
  2017-12-14 19:40 ` [libnftnl PATCH 1/6] nftnl_data_reg_snprintf: Add a missing break Phil Sutter
  2017-12-14 19:40 ` [libnftnl PATCH 2/6] src/gen: Remove a pointless call to mnl_nlmsg_get_payload() Phil Sutter
@ 2017-12-14 19:40 ` Phil Sutter
  2017-12-15 15:18   ` Pablo Neira Ayuso
  2017-12-14 19:40 ` [libnftnl PATCH 4/6] src/ruleset: Avoid reading garbage in nftnl_ruleset_cb() Phil Sutter
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Phil Sutter @ 2017-12-14 19:40 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

It may happen that 'perr' variable does not get initialized, so making
parameter 'err' point to it in any case is error-prone. Avoid this by
initializing 'perr' upon declaration.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 src/object.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/object.c b/src/object.c
index 9a4ee712a2a95..da3423bf3381a 100644
--- a/src/object.c
+++ b/src/object.c
@@ -358,7 +358,7 @@ static int nftnl_obj_do_parse(struct nftnl_obj *obj, enum nftnl_parse_type type,
 			      const void *data, struct nftnl_parse_err *err,
 			      enum nftnl_parse_input input)
 {
-	struct nftnl_parse_err perr;
+	struct nftnl_parse_err perr = {};
 	int ret;
 
 	switch (type) {
-- 
2.13.1


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

* [libnftnl PATCH 4/6] src/ruleset: Avoid reading garbage in nftnl_ruleset_cb()
  2017-12-14 19:40 [libnftnl PATCH 0/6] Another round of Covscan indicated fixes Phil Sutter
                   ` (2 preceding siblings ...)
  2017-12-14 19:40 ` [libnftnl PATCH 3/6] src/object: Avoid returning garbage in nftnl_obj_do_parse() Phil Sutter
@ 2017-12-14 19:40 ` Phil Sutter
  2017-12-15 15:18   ` Pablo Neira Ayuso
  2017-12-14 19:40 ` [libnftnl PATCH 5/6] src/set_elem: Don't return garbage in nftnl_set_elems_parse() Phil Sutter
  2017-12-14 19:40 ` [libnftnl PATCH 6/6] src/trace: Check return value of mnl_attr_parse_nested() Phil Sutter
  5 siblings, 1 reply; 13+ messages in thread
From: Phil Sutter @ 2017-12-14 19:40 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

If nftnl_ruleset_json_parse() is called with arg == NULL, ctx.data is
left uninitialized and will later be used in nftnl_ruleset_cb(). Avoid
this by using a C99-style initializer for 'ctx' which sets all omitted
fields to zero.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 src/ruleset.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/ruleset.c b/src/ruleset.c
index 3de9b87283292..cf86ca68a51f3 100644
--- a/src/ruleset.c
+++ b/src/ruleset.c
@@ -519,11 +519,11 @@ static int nftnl_ruleset_json_parse(const void *json,
 	json_error_t error;
 	int i, len;
 	const char *key;
-	struct nftnl_parse_ctx ctx;
-
-	ctx.cb = cb;
-	ctx.format = type;
-	ctx.flags = 0;
+	struct nftnl_parse_ctx ctx = {
+		.cb = cb,
+		.format = type,
+		.flags = 0,
+	};
 
 	ctx.set_list = nftnl_set_list_alloc();
 	if (ctx.set_list == NULL)
-- 
2.13.1


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

* [libnftnl PATCH 5/6] src/set_elem: Don't return garbage in nftnl_set_elems_parse()
  2017-12-14 19:40 [libnftnl PATCH 0/6] Another round of Covscan indicated fixes Phil Sutter
                   ` (3 preceding siblings ...)
  2017-12-14 19:40 ` [libnftnl PATCH 4/6] src/ruleset: Avoid reading garbage in nftnl_ruleset_cb() Phil Sutter
@ 2017-12-14 19:40 ` Phil Sutter
  2017-12-15 15:19   ` Pablo Neira Ayuso
  2017-12-14 19:40 ` [libnftnl PATCH 6/6] src/trace: Check return value of mnl_attr_parse_nested() Phil Sutter
  5 siblings, 1 reply; 13+ messages in thread
From: Phil Sutter @ 2017-12-14 19:40 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

This might happen if netlink message is malformed (no nested attributes
are present), so treat this as an error and return -1 instead of
garbage to caller.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 src/set_elem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/set_elem.c b/src/set_elem.c
index e45dbc6bfe3e4..71c279a540860 100644
--- a/src/set_elem.c
+++ b/src/set_elem.c
@@ -490,7 +490,7 @@ nftnl_set_elem_list_parse_attr_cb(const struct nlattr *attr, void *data)
 static int nftnl_set_elems_parse(struct nftnl_set *s, const struct nlattr *nest)
 {
 	struct nlattr *attr;
-	int ret;
+	int ret = -1;
 
 	mnl_attr_for_each_nested(attr, nest) {
 		if (mnl_attr_get_type(attr) != NFTA_LIST_ELEM)
-- 
2.13.1


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

* [libnftnl PATCH 6/6] src/trace: Check return value of mnl_attr_parse_nested()
  2017-12-14 19:40 [libnftnl PATCH 0/6] Another round of Covscan indicated fixes Phil Sutter
                   ` (4 preceding siblings ...)
  2017-12-14 19:40 ` [libnftnl PATCH 5/6] src/set_elem: Don't return garbage in nftnl_set_elems_parse() Phil Sutter
@ 2017-12-14 19:40 ` Phil Sutter
  2017-12-15 15:20   ` Pablo Neira Ayuso
  5 siblings, 1 reply; 13+ messages in thread
From: Phil Sutter @ 2017-12-14 19:40 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

This is done everywhere else as well, so certainly not a bad thing here
either.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 src/trace.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/trace.c b/src/trace.c
index bd05d3c58d2fa..b016e723a7ded 100644
--- a/src/trace.c
+++ b/src/trace.c
@@ -301,7 +301,8 @@ static int nftnl_trace_parse_verdict(const struct nlattr *attr,
 {
 	struct nlattr *tb[NFTA_VERDICT_MAX+1];
 
-	mnl_attr_parse_nested(attr, nftnl_trace_parse_verdict_cb, tb);
+	if (mnl_attr_parse_nested(attr, nftnl_trace_parse_verdict_cb, tb) < 0)
+		return -1;
 
 	if (!tb[NFTA_VERDICT_CODE])
 		abi_breakage();
-- 
2.13.1


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

* Re: [libnftnl PATCH 1/6] nftnl_data_reg_snprintf: Add a missing break
  2017-12-14 19:40 ` [libnftnl PATCH 1/6] nftnl_data_reg_snprintf: Add a missing break Phil Sutter
@ 2017-12-15 15:17   ` Pablo Neira Ayuso
  0 siblings, 0 replies; 13+ messages in thread
From: Pablo Neira Ayuso @ 2017-12-15 15:17 UTC (permalink / raw)
  To: Phil Sutter; +Cc: netfilter-devel

On Thu, Dec 14, 2017 at 08:40:20PM +0100, Phil Sutter wrote:
> The code works fine as-is, but if reg_type == DATA_VALUE &&
> output_format == NFTNL_OUTPUT_XML, we fall through to DATA_CHAIN case
> and therefore pointlessly check output_format again.
> 
> Signed-off-by: Phil Sutter <phil@nwl.cc>
> ---
>  src/expr/data_reg.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/src/expr/data_reg.c b/src/expr/data_reg.c
> index a246952f7f01b..c087d792a8af6 100644
> --- a/src/expr/data_reg.c
> +++ b/src/expr/data_reg.c
> @@ -207,6 +207,7 @@ int nftnl_data_reg_snprintf(char *buf, size_t size,
>  		default:
>  			break;
>  		}
> +		break;
>  	case DATA_VERDICT:
>  	case DATA_CHAIN:
>  		switch(output_format) {

I'm going to add a break also at the end of 'case DATA_CHAIN:', recent
gcc can spot warning on implicit fall through without comments, so
let's fix that spot too.

Applied, thanks!

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

* Re: [libnftnl PATCH 2/6] src/gen: Remove a pointless call to mnl_nlmsg_get_payload()
  2017-12-14 19:40 ` [libnftnl PATCH 2/6] src/gen: Remove a pointless call to mnl_nlmsg_get_payload() Phil Sutter
@ 2017-12-15 15:17   ` Pablo Neira Ayuso
  0 siblings, 0 replies; 13+ messages in thread
From: Pablo Neira Ayuso @ 2017-12-15 15:17 UTC (permalink / raw)
  To: Phil Sutter; +Cc: netfilter-devel

On Thu, Dec 14, 2017 at 08:40:21PM +0100, Phil Sutter wrote:
> It is a common idiom in all *_nlmsg_parse() functions, but
> nftnl_gen_nlmsg_parse() doesn't make use of the data pointer and the
> compiler probably can't eliminate it since there could be a side-effect.

Also applied, thanks.

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

* Re: [libnftnl PATCH 3/6] src/object: Avoid returning garbage in nftnl_obj_do_parse()
  2017-12-14 19:40 ` [libnftnl PATCH 3/6] src/object: Avoid returning garbage in nftnl_obj_do_parse() Phil Sutter
@ 2017-12-15 15:18   ` Pablo Neira Ayuso
  0 siblings, 0 replies; 13+ messages in thread
From: Pablo Neira Ayuso @ 2017-12-15 15:18 UTC (permalink / raw)
  To: Phil Sutter; +Cc: netfilter-devel

On Thu, Dec 14, 2017 at 08:40:22PM +0100, Phil Sutter wrote:
> It may happen that 'perr' variable does not get initialized, so making
> parameter 'err' point to it in any case is error-prone. Avoid this by
> initializing 'perr' upon declaration.

Applied, thanks.

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

* Re: [libnftnl PATCH 4/6] src/ruleset: Avoid reading garbage in nftnl_ruleset_cb()
  2017-12-14 19:40 ` [libnftnl PATCH 4/6] src/ruleset: Avoid reading garbage in nftnl_ruleset_cb() Phil Sutter
@ 2017-12-15 15:18   ` Pablo Neira Ayuso
  0 siblings, 0 replies; 13+ messages in thread
From: Pablo Neira Ayuso @ 2017-12-15 15:18 UTC (permalink / raw)
  To: Phil Sutter; +Cc: netfilter-devel

On Thu, Dec 14, 2017 at 08:40:23PM +0100, Phil Sutter wrote:
> If nftnl_ruleset_json_parse() is called with arg == NULL, ctx.data is
> left uninitialized and will later be used in nftnl_ruleset_cb(). Avoid
> this by using a C99-style initializer for 'ctx' which sets all omitted
> fields to zero.

Applied, thanks Phil.

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

* Re: [libnftnl PATCH 5/6] src/set_elem: Don't return garbage in nftnl_set_elems_parse()
  2017-12-14 19:40 ` [libnftnl PATCH 5/6] src/set_elem: Don't return garbage in nftnl_set_elems_parse() Phil Sutter
@ 2017-12-15 15:19   ` Pablo Neira Ayuso
  0 siblings, 0 replies; 13+ messages in thread
From: Pablo Neira Ayuso @ 2017-12-15 15:19 UTC (permalink / raw)
  To: Phil Sutter; +Cc: netfilter-devel

On Thu, Dec 14, 2017 at 08:40:24PM +0100, Phil Sutter wrote:
> This might happen if netlink message is malformed (no nested attributes
> are present), so treat this as an error and return -1 instead of
> garbage to caller.

Applied, thanks.

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

* Re: [libnftnl PATCH 6/6] src/trace: Check return value of mnl_attr_parse_nested()
  2017-12-14 19:40 ` [libnftnl PATCH 6/6] src/trace: Check return value of mnl_attr_parse_nested() Phil Sutter
@ 2017-12-15 15:20   ` Pablo Neira Ayuso
  0 siblings, 0 replies; 13+ messages in thread
From: Pablo Neira Ayuso @ 2017-12-15 15:20 UTC (permalink / raw)
  To: Phil Sutter; +Cc: netfilter-devel

On Thu, Dec 14, 2017 at 08:40:25PM +0100, Phil Sutter wrote:
> This is done everywhere else as well, so certainly not a bad thing here
> either.

Indeed. Applied, thanks Phil.

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

end of thread, other threads:[~2017-12-15 15:20 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-14 19:40 [libnftnl PATCH 0/6] Another round of Covscan indicated fixes Phil Sutter
2017-12-14 19:40 ` [libnftnl PATCH 1/6] nftnl_data_reg_snprintf: Add a missing break Phil Sutter
2017-12-15 15:17   ` Pablo Neira Ayuso
2017-12-14 19:40 ` [libnftnl PATCH 2/6] src/gen: Remove a pointless call to mnl_nlmsg_get_payload() Phil Sutter
2017-12-15 15:17   ` Pablo Neira Ayuso
2017-12-14 19:40 ` [libnftnl PATCH 3/6] src/object: Avoid returning garbage in nftnl_obj_do_parse() Phil Sutter
2017-12-15 15:18   ` Pablo Neira Ayuso
2017-12-14 19:40 ` [libnftnl PATCH 4/6] src/ruleset: Avoid reading garbage in nftnl_ruleset_cb() Phil Sutter
2017-12-15 15:18   ` Pablo Neira Ayuso
2017-12-14 19:40 ` [libnftnl PATCH 5/6] src/set_elem: Don't return garbage in nftnl_set_elems_parse() Phil Sutter
2017-12-15 15:19   ` Pablo Neira Ayuso
2017-12-14 19:40 ` [libnftnl PATCH 6/6] src/trace: Check return value of mnl_attr_parse_nested() Phil Sutter
2017-12-15 15:20   ` Pablo Neira Ayuso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.