aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/tortls.c3
-rw-r--r--src/common/util.c15
-rw-r--r--src/common/util.h1
3 files changed, 18 insertions, 1 deletions
diff --git a/src/common/tortls.c b/src/common/tortls.c
index 1f943ebb8..5d0ead1c4 100644
--- a/src/common/tortls.c
+++ b/src/common/tortls.c
@@ -421,7 +421,7 @@ tor_tls_verify(tor_tls *tls)
time_t now;
crypto_pk_env_t *r = NULL;
if (!(cert = SSL_get_peer_certificate(tls->ssl)))
- return 0;
+ return NULL;
now = time(NULL);
if (X509_cmp_time(X509_get_notBefore(cert), &now) > 0)
@@ -453,3 +453,4 @@ tor_tls_verify(tor_tls *tls)
RSA_free(rsa);
return r;
}
+
diff --git a/src/common/util.c b/src/common/util.c
index 21584093c..c942c5d73 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -103,6 +103,21 @@ int write_all(int fd, const void *buf, size_t count) {
return count;
}
+/* a wrapper for read(2) that makes sure to read all count bytes.
+ * Only use if fd is a blocking socket. */
+int read_all(int fd, void *buf, size_t count) {
+ int numread = 0;
+ int result;
+
+ while(numread != count) {
+ result = read(fd, buf+numread, count-numread);
+ if(result<=0)
+ return -1;
+ numread += result;
+ }
+ return count;
+}
+
void set_socket_nonblocking(int socket)
{
#ifdef MS_WINDOWS
diff --git a/src/common/util.h b/src/common/util.h
index 8552fb19a..94fcd512d 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -52,6 +52,7 @@ void tv_add(struct timeval *a, struct timeval *b);
int tv_cmp(struct timeval *a, struct timeval *b);
int write_all(int fd, const void *buf, size_t count);
+int read_all(int fd, void *buf, size_t count);
void set_socket_nonblocking(int socket);