aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaks Mishin <maks.mishinfz@gmail.com>2024-01-06 22:04:23 +0300
committerStephen Hemminger <stephen@networkplumber.org>2024-01-08 09:31:51 -0800
commita193733b7a7ef1e65e1b88045c32f96ed16caeb9 (patch)
treecc525a7b506fbd985d0df0e6b604c804472e4b14
parent3a882b6b4e0ee8c7cfd11176d36a98d30fc449d3 (diff)
downloadiproute2-a193733b7a7ef1e65e1b88045c32f96ed16caeb9.tar.gz
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 Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
-rw-r--r--misc/lnstat.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/misc/lnstat.c b/misc/lnstat.c
index c3f2999cc..f802a0f35 100644
--- a/misc/lnstat.c
+++ b/misc/lnstat.c
@@ -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;