From d7e5021416444e3cc545ffa4f8d1e613cabec633 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Thu, 22 Apr 2021 13:26:50 +0200 Subject: Check malloc calls in process.c Fixes warnings like warning[-Wanalyzer-possible-null-argument]: use of possibly-NULL 'authdata' where non-null expected Found-by: gcc static analysis Signed-off-by: Karol Herbst --- process.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/process.c b/process.c index 5d4f22b..50d82b0 100644 --- a/process.c +++ b/process.c @@ -1639,11 +1639,19 @@ do_add(const char *inputfilename, int lineno, int argc, const char **argv) len = strlen(hexkey); if (len > 1 && hexkey[0] == '"' && hexkey[len-1] == '"') { key = malloc(len-1); + if (!key) { + fprintf(stderr, "unable to allocate memory\n"); + return 1; + } strncpy(key, hexkey+1, len-2); len -= 2; } else if (!strcmp(protoname, SECURERPC) || !strcmp(protoname, K5AUTH)) { key = malloc(len+1); + if (!key) { + fprintf(stderr, "unable to allocate memory\n"); + return 1; + } strcpy(key, hexkey); } else { len = cvthexkey (hexkey, &key); @@ -1947,6 +1955,11 @@ do_generate(const char *inputfilename, int lineno, int argc, const char **argv) authdatalen = strlen(hexdata); if (hexdata[0] == '"' && hexdata[authdatalen-1] == '"') { authdata = malloc(authdatalen-1); + if (!authdata) { + fprintf(stderr, "unable to allocate memory\n"); + status = 1; + goto exit_generate; + } strncpy(authdata, hexdata+1, authdatalen-2); authdatalen -= 2; } else { -- cgit v1.2.3