diff options
author | Karol Herbst <kherbst@redhat.com> | 2021-04-22 13:26:50 +0200 |
---|---|---|
committer | Karol Herbst <kherbst@redhat.com> | 2021-04-22 13:30:14 +0200 |
commit | d7e5021416444e3cc545ffa4f8d1e613cabec633 (patch) | |
tree | 923603ce1bf9dfa079a9afab784eaf31e375d587 | |
parent | 18a3c3a7672ff5d65bf0b79b89464eac7540b95b (diff) | |
download | xorg-app-xauth-d7e5021416444e3cc545ffa4f8d1e613cabec633.tar.gz |
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 <kherbst@redhat.com>
-rw-r--r-- | process.c | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -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 { |