summaryrefslogtreecommitdiff
path: root/src/common/util.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2015-07-15 10:35:29 -0400
committerNick Mathewson <nickm@torproject.org>2015-07-15 10:35:29 -0400
commit3c28d95ca7c1f7086c2f840254a2d6663beaf935 (patch)
treeb90b857aff3906991532498e7bf1158ac8924a1f /src/common/util.c
parent5e8edba3d80bf53e5e5c09c8a87e06d0c69e00b7 (diff)
downloadtor-3c28d95ca7c1f7086c2f840254a2d6663beaf935.tar.gz
tor-3c28d95ca7c1f7086c2f840254a2d6663beaf935.zip
Add more EINVAL errno setting on key read failures
Teor found these. This is for part of #16582.
Diffstat (limited to 'src/common/util.c')
-rw-r--r--src/common/util.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/common/util.c b/src/common/util.c
index a140057dea..1849613512 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -1997,8 +1997,10 @@ read_all(tor_socket_t fd, char *buf, size_t count, int isSocket)
size_t numread = 0;
ssize_t result;
- if (count > SIZE_T_CEILING || count > SSIZE_MAX)
+ if (count > SIZE_T_CEILING || count > SSIZE_MAX) {
+ errno = EINVAL;
return -1;
+ }
while (numread != count) {
if (isSocket)
@@ -2558,8 +2560,10 @@ read_file_to_str_until_eof(int fd, size_t max_bytes_to_read, size_t *sz_out)
char *string = NULL;
size_t string_max = 0;
- if (max_bytes_to_read+1 >= SIZE_T_CEILING)
+ if (max_bytes_to_read+1 >= SIZE_T_CEILING) {
+ errno = EINVAL;
return NULL;
+ }
do {
/* XXXX This "add 1K" approach is a little goofy; if we care about
@@ -2655,6 +2659,7 @@ read_file_to_str(const char *filename, int flags, struct stat *stat_out)
if ((uint64_t)(statbuf.st_size)+1 >= SIZE_T_CEILING) {
close(fd);
+ errno = EINVAL;
return NULL;
}