Skip to contentSkip to conversation

monitor: Fix for incorrect debug_mask

PATCH Applied Phil Sutter 2 participants 2 messages Sep 21, 2017 – Sep 27, 2017 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/1 monitor: Fix for incorrect debug_mask

The field 'debug_mask' of struct netlink_mon_handler was left uninitialized in do_command_monitor() so it contained garbage from the stack. Fix this by initializing it with the debug_mask value from struct netlink_ctx.

While being at it, change the code to make use of C99-style initializer, which will also avoid things like this in future.

Fixes be441e1ffdc24 ("src: add debugging mask to context structure")
---
 src/rule.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
src/rule.c +8 -7
index 1bb7b4756171c..8f0e752f21fba 100644
@@ -1690,7 +1690,14 @@ static int do_command_monitor(struct netlink_ctx *ctx, struct cmd *cmd)
 {
 	struct table *t;
 	struct set *s;
-	struct netlink_mon_handler monhandler;
+	struct netlink_mon_handler monhandler = {
+		.monitor_flags	= cmd->monitor->flags,
+		.format		= cmd->monitor->format,
+		.ctx		= ctx,
+		.loc		= &cmd->location,
+		.cache		= ctx->cache,
+		.debug_mask	= ctx->debug_mask,
+	};
 
 	monhandler.cache_needed = need_cache(cmd);
 	if (monhandler.cache_needed) {
@@ -1725,12 +1732,6 @@ static int do_command_monitor(struct netlink_ctx *ctx, struct cmd *cmd)
 		}
 	}
 
-	monhandler.monitor_flags = cmd->monitor->flags;
-	monhandler.format = cmd->monitor->format;
-	monhandler.ctx = ctx;
-	monhandler.loc = &cmd->location;
-	monhandler.cache = ctx->cache;
-
 	return netlink_monitor(&monhandler, ctx->nf_sock);
 }
 
Signature · 1 line
2.13.1
maintainer Applied
#1 lore raw
Quoted 7 lines · Phil Sutter

The field 'debug_mask' of struct netlink_mon_handler was left uninitialized in do_command_monitor() so it contained garbage from the stack. Fix this by initializing it with the debug_mask value from struct netlink_ctx.

While being at it, change the code to make use of C99-style initializer, which will also avoid things like this in future.

Applied, thanks Phil.