summaryrefslogtreecommitdiff
path: root/lib/libtls/tls_config.c
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2016-11-04 18:59:36 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2016-11-04 18:59:36 +0000
commit2068871418ff5e444becdf8fc21c932513e0cd92 (patch)
treedded6af6e4296f80dd0782acca173c92c73e8b1e /lib/libtls/tls_config.c
parentfa480c08f689f9cb0e09cdea71949ef1a03fd585 (diff)
Avoid another signed vs unsigned comparison.
ok miod@
Diffstat (limited to 'lib/libtls/tls_config.c')
-rw-r--r--lib/libtls/tls_config.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/libtls/tls_config.c b/lib/libtls/tls_config.c
index 5c73c29d659..f727328f874 100644
--- a/lib/libtls/tls_config.c
+++ b/lib/libtls/tls_config.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tls_config.c,v 1.29 2016/11/04 05:13:13 beck Exp $ */
+/* $OpenBSD: tls_config.c,v 1.30 2016/11/04 18:59:35 jsing Exp $ */
/*
* Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
*
@@ -128,6 +128,7 @@ tls_config_load_file(struct tls_error *error, const char *filetype,
{
struct stat st;
int fd = -1;
+ ssize_t n;
free(*buf);
*buf = NULL;
@@ -143,13 +144,16 @@ tls_config_load_file(struct tls_error *error, const char *filetype,
filetype, filename);
goto fail;
}
+ if (st.st_size < 0)
+ goto fail;
*len = (size_t)st.st_size;
if ((*buf = malloc(*len)) == NULL) {
tls_error_set(error, "failed to allocate buffer for "
"%s file", filetype);
goto fail;
}
- if (read(fd, *buf, *len) != *len) {
+ n = read(fd, *buf, *len);
+ if (n < 0 || (size_t)n != *len) {
tls_error_set(error, "failed to read %s file '%s'",
filetype, filename);
goto fail;