]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
lnstat: Fix deref of null in print_json() function
authorMaks Mishin <maks.mishinfz@gmail.com>
Sat, 6 Jan 2024 19:04:23 +0000 (22:04 +0300)
committerStephen Hemminger <stephen@networkplumber.org>
Mon, 8 Jan 2024 17:31:51 +0000 (09:31 -0800)
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

Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
misc/lnstat.c

index c3f2999cc2558445888181e72203fe86d1fa44cb..f802a0f354da99b14ad600e1e7bb222107549886 100644 (file)
@@ -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;