Skip to contentSkip to conversation

main: Fix for return of uninitialized variable in nft_run_cmd_from_filename()

PATCH In review 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 main: Fix for return of uninitialized variable in nft_run_cmd_from_filename()

If scanner_read_file() failed, the function would return an uninitialized value.

Fixes 3db28321b64a6 ("src: add nft_run_cmd_*() functions")
---
 src/main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
src/main.c +3 -1
index 702ef30237b3b..8e7b586d347cc 100644
@@ -351,8 +351,10 @@ static int nft_run_cmd_from_filename(struct nft_ctx *nft, const char *filename)
 
 	parser_init(nft->nf_sock, &nft->cache, &state, &msgs, nft->debug_mask);
 	scanner = scanner_init(&state);
-	if (scanner_read_file(scanner, filename, &internal_location) < 0)
+	if (scanner_read_file(scanner, filename, &internal_location) < 0) {
+		rc = NFT_EXIT_FAILURE;
 		goto err;
+	}
 
 	if (nft_run(nft, nft->nf_sock, scanner, &state, &msgs) != 0)
 		rc = NFT_EXIT_FAILURE;
Signature · 1 line
2.13.1
#1 lore raw
Quoted 2 lines · Phil Sutter

If scanner_read_file() failed, the function would return an uninitialized value.

Also applied, thanks.