summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarol Herbst <kherbst@redhat.com>2021-04-22 13:26:50 +0200
committerKarol Herbst <kherbst@redhat.com>2021-04-22 13:30:14 +0200
commitd7e5021416444e3cc545ffa4f8d1e613cabec633 (patch)
tree923603ce1bf9dfa079a9afab784eaf31e375d587
parent18a3c3a7672ff5d65bf0b79b89464eac7540b95b (diff)
downloadxorg-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.c13
1 files changed, 13 insertions, 0 deletions
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 {