summaryrefslogtreecommitdiff
path: root/src/common/util.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2015-07-14 10:18:52 -0400
committerNick Mathewson <nickm@torproject.org>2015-07-14 10:18:52 -0400
commitb566cb9e84b095289a1c662e953218c9a7d1f77d (patch)
tree468a88d00dde062816f05df3afc7794c90d96a68 /src/common/util.c
parentb06759edfda17205b8a027b2a369abefcaaba4fc (diff)
downloadtor-b566cb9e84b095289a1c662e953218c9a7d1f77d.tar.gz
tor-b566cb9e84b095289a1c662e953218c9a7d1f77d.zip
Make file-reading and key-reading preserve errno
This is an important part of #16582.
Diffstat (limited to 'src/common/util.c')
-rw-r--r--src/common/util.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 449015054f..a140057dea 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -2571,7 +2571,9 @@ read_file_to_str_until_eof(int fd, size_t max_bytes_to_read, size_t *sz_out)
string = tor_realloc(string, string_max);
r = read(fd, string + pos, string_max - pos - 1);
if (r < 0) {
+ int save_errno = errno;
tor_free(string);
+ errno = save_errno;
return NULL;
}
@@ -2639,11 +2641,14 @@ read_file_to_str(const char *filename, int flags, struct stat *stat_out)
if (S_ISFIFO(statbuf.st_mode)) {
size_t sz = 0;
string = read_file_to_str_until_eof(fd, FIFO_READ_MAX, &sz);
+ int save_errno = errno;
if (string && stat_out) {
statbuf.st_size = sz;
memcpy(stat_out, &statbuf, sizeof(struct stat));
}
close(fd);
+ if (!string)
+ errno = save_errno;
return string;
}
#endif