diff options
-rw-r--r-- | usr.sbin/rpki-client/encoding.c | 17 | ||||
-rw-r--r-- | usr.sbin/rpki-client/main.c | 6 |
2 files changed, 18 insertions, 5 deletions
diff --git a/usr.sbin/rpki-client/encoding.c b/usr.sbin/rpki-client/encoding.c index 55c22a8cd82..269f861be53 100644 --- a/usr.sbin/rpki-client/encoding.c +++ b/usr.sbin/rpki-client/encoding.c @@ -1,4 +1,4 @@ -/* $OpenBSD: encoding.c,v 1.8 2021/10/28 11:57:00 claudio Exp $ */ +/* $OpenBSD: encoding.c,v 1.9 2021/10/31 16:00:14 claudio Exp $ */ /* * Copyright (c) 2020 Claudio Jeker <claudio@openbsd.org> * @@ -17,6 +17,7 @@ #include <sys/stat.h> #include <err.h> +#include <errno.h> #include <fcntl.h> #include <limits.h> #include <stdlib.h> @@ -37,7 +38,7 @@ load_file(const char *name, size_t *len) struct stat st; ssize_t n; size_t size; - int fd; + int fd, saved_errno; *len = 0; @@ -45,21 +46,29 @@ load_file(const char *name, size_t *len) return NULL; if (fstat(fd, &st) != 0) goto err; - if (st.st_size < 0 || st.st_size > MAX_FILE_SIZE) + if (st.st_size <= 0 || st.st_size > MAX_FILE_SIZE) { + errno = EFBIG; goto err; + } size = (size_t)st.st_size; if ((buf = malloc(size)) == NULL) goto err; n = read(fd, buf, size); - if (n < 0 || (size_t)n != size) + if (n == -1) + goto err; + if ((size_t)n != size) { + errno = EIO; goto err; + } close(fd); *len = size; return buf; err: + saved_errno = errno; close(fd); free(buf); + errno = saved_errno; return NULL; } diff --git a/usr.sbin/rpki-client/main.c b/usr.sbin/rpki-client/main.c index a56aa6571fc..33f9b0fb4d3 100644 --- a/usr.sbin/rpki-client/main.c +++ b/usr.sbin/rpki-client/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.158 2021/10/31 15:58:13 claudio Exp $ */ +/* $OpenBSD: main.c,v 1.159 2021/10/31 16:00:14 claudio Exp $ */ /* * Copyright (c) 2021 Claudio Jeker <claudio@openbsd.org> * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> @@ -393,6 +393,10 @@ queue_add_tal(const char *file) if ((nfile = strdup(file)) == NULL) err(1, NULL); buf = load_file(file, &len); + if (buf == NULL) { + warn("%s", file); + return; + } /* Record tal for later reporting */ if (stats.talnames == NULL) { |