From fb5ae095e936833093924b3aba7cb89eb5420b54 Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Wed, 3 Mar 2021 10:15:18 -0600 Subject: [PATCH] asn1: Fix warnings --- lib/asn1/asn1_print.c | 2 +- lib/asn1/check-common.c | 18 +++++++++++------- lib/asn1/der_put.c | 16 ++++++++++------ 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/asn1/asn1_print.c b/lib/asn1/asn1_print.c index 2165a6610..dbee37748 100644 --- a/lib/asn1/asn1_print.c +++ b/lib/asn1/asn1_print.c @@ -357,7 +357,7 @@ dotype(unsigned char *buf, size_t len, char **argv, size_t *size) size_t matches = 0; size_t sz; size_t i = 0; - char *s; + char *s = NULL; void *v; int ret = 0; diff --git a/lib/asn1/check-common.c b/lib/asn1/check-common.c index 7eadc0109..95999709b 100644 --- a/lib/asn1/check-common.c +++ b/lib/asn1/check-common.c @@ -175,17 +175,21 @@ segv_handler(int sig) { int fd; char msg[] = "SIGSEGV i current test: "; + /* For compilers that insist we check write(2)'s result here */ + int e = 1; fd = open("/dev/stdout", O_WRONLY, 0600); if (fd >= 0) { - write(fd, msg, sizeof(msg)); - write(fd, current_test, strlen(current_test)); - write(fd, " ", 1); - write(fd, current_state, strlen(current_state)); - write(fd, "\n", 1); - close(fd); + + if (write(fd, msg, sizeof(msg)) == -1 || + write(fd, current_test, strlen(current_test)) == -1 || + write(fd, " ", 1) == -1 || + write(fd, current_state, strlen(current_state)) == -1 || + write(fd, "\n", 1) == -1) + e = 2; + (void) close(fd); } - _exit(1); + _exit(e); } int diff --git a/lib/asn1/der_put.c b/lib/asn1/der_put.c index 9a5e7a356..122dbf7cc 100644 --- a/lib/asn1/der_put.c +++ b/lib/asn1/der_put.c @@ -597,6 +597,7 @@ _heim_time2generalizedtime (time_t t, heim_octet_string *s, int gtimep) { struct tm tm; const size_t len = gtimep ? 15 : 13; + int bytes; s->data = NULL; s->length = 0; @@ -607,13 +608,16 @@ _heim_time2generalizedtime (time_t t, heim_octet_string *s, int gtimep) return ENOMEM; s->length = len; if (gtimep) - snprintf (s->data, len + 1, "%04d%02d%02d%02d%02d%02dZ", - tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec); + bytes = snprintf(s->data, len + 1, "%04d%02d%02d%02d%02d%02dZ", + tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, + tm.tm_hour, tm.tm_min, tm.tm_sec); else - snprintf (s->data, len + 1, "%02d%02d%02d%02d%02d%02dZ", - tm.tm_year % 100, tm.tm_mon + 1, tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec); + bytes = snprintf(s->data, len + 1, "%02d%02d%02d%02d%02d%02dZ", + tm.tm_year % 100, tm.tm_mon + 1, tm.tm_mday, + tm.tm_hour, tm.tm_min, tm.tm_sec); + + if (bytes > len) + abort(); return 0; }