Skip to contentSkip to conversation

lnstat: Fix deref of null in print_json() function

PATCH Applied Maks Mishin 3 participants 3 messages Jan 6, 2024 – Jan 8, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lnstat: Fix deref of null in print_json() function

Now pointer jw is being checked for NULL before using in function jsonw_start_object.
Added exit from function when jw==NULL.

Found by RASU JSC

---
 misc/lnstat.c | 4 ++++
 1 file changed, 4 insertions(+)
misc/lnstat.c +4 -0
index c3f2999c..f802a0f3 100644
@@ -112,6 +112,10 @@ static void print_json(FILE *of, const struct lnstat_file *lnstat_files,
 	json_writer_t *jw = jsonw_new(of);
 	int i;
 
+	if (jw == NULL) {
+		fprintf(stderr, "Failed to create JSON writer\n");
+		exit(1);
+	}
 	jsonw_start_object(jw);
 	for (i = 0; i < fp->num; i++) {
 		const struct lnstat_field *lf = fp->params[i].lf;
Signature · 1 line
2.34.1
#1 lore raw
Quoted 7 lines · On Sat, 6 Jan 2024 22:04:23 +0300 Maks Mishin <[email protected]> wrote:

Now pointer jw is being checked for NULL before using in function jsonw_start_object.
Added exit from function when jw==NULL.

Found by RASU JSC

Probably not worth fixing.
If the malloc() of 20 bytes ever fails then something is really wrong. The Linux kernel will kill the process first.

#2 lore raw
In reply to Maks Mishin
This patch was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:

Hello:

This patch was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:

Quoted 9 lines · On Sat, 6 Jan 2024 22:04:23 +0300 you wrote:

Now pointer jw is being checked for NULL before using in function jsonw_start_object.
Added exit from function when jw==NULL.

Found by RASU JSC

[...]

Here is the summary with links:
- lnstat: Fix deref of null in print_json() function

    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=a193733b7a7e

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html