diff options
author | Ole Troan <ot@cisco.com> | 2021-08-31 14:21:03 +0200 |
---|---|---|
committer | Damjan Marion <dmarion@me.com> | 2021-08-31 15:26:29 +0000 |
commit | 6b3eeebacf8ee5c5be56b98c62a696f19e518e84 (patch) | |
tree | 8814eea1313f804ed473c90f1ce8850edc53a5b1 /src/vat2/main.c | |
parent | 43eb6083c5819062c4d65bf3a2072ac67939a1f2 (diff) |
vat2: coverity errors in print_template
Dereferencing null pointer fix.
Add checking of return values for all calls in print_template()
Type: fix
Signed-off-by: Ole Troan <ot@cisco.com>
Change-Id: I00073b29ab2e76d5d06af9bd3f5ae2846de4d46d
Diffstat (limited to 'src/vat2/main.c')
-rw-r--r-- | src/vat2/main.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/vat2/main.c b/src/vat2/main.c index b3606f3dd98..208e0c5d2c2 100644 --- a/src/vat2/main.c +++ b/src/vat2/main.c @@ -151,21 +151,36 @@ print_template (char *msgname) { uword *p = hash_get_mem (function_by_name, msgname); if (!p) - { - fprintf (stderr, "no such message: %s", msgname); - } + goto error; + cJSON *(*fp) (void *); fp = (void *) apifuncs[p[0]].tojson; - assert (fp); + if (!fp) + goto error; + void *scratch = malloc (2048); + if (!scratch) + goto error; + memset (scratch, 0, 2048); cJSON *t = fp (scratch); + if (!t) + goto error; free (scratch); char *output = cJSON_Print (t); + if (!output) + goto error; + cJSON_Delete (t); printf ("%s\n", output); free (output); + + return; + +error: + fprintf (stderr, "error printing template for: %s\n", msgname); } + static void dump_apis (void) { |