summaryrefslogtreecommitdiffstats
path: root/src/crypto/bio
diff options
context:
space:
mode:
Diffstat (limited to 'src/crypto/bio')
-rw-r--r--src/crypto/bio/CMakeLists.txt2
-rw-r--r--src/crypto/bio/bio.c9
-rw-r--r--src/crypto/bio/bio_test.cc3
-rw-r--r--src/crypto/bio/printf.c6
-rw-r--r--src/crypto/bio/socket_helper.c2
5 files changed, 14 insertions, 8 deletions
diff --git a/src/crypto/bio/CMakeLists.txt b/src/crypto/bio/CMakeLists.txt
index f4122c4..dbf5951 100644
--- a/src/crypto/bio/CMakeLists.txt
+++ b/src/crypto/bio/CMakeLists.txt
@@ -22,6 +22,8 @@ add_executable(
bio_test
bio_test.cc
+
+ $<TARGET_OBJECTS:test_support>
)
target_link_libraries(bio_test crypto)
diff --git a/src/crypto/bio/bio.c b/src/crypto/bio/bio.c
index 694a11c..5ac5911 100644
--- a/src/crypto/bio/bio.c
+++ b/src/crypto/bio/bio.c
@@ -65,6 +65,8 @@
#include <openssl/mem.h>
#include <openssl/thread.h>
+#include "../internal.h"
+
/* BIO_set initialises a BIO structure to have the given type and sets the
* reference count to one. It returns one on success or zero on error. */
@@ -104,8 +106,7 @@ int BIO_free(BIO *bio) {
BIO *next_bio;
for (; bio != NULL; bio = next_bio) {
- int refs = CRYPTO_add(&bio->references, -1, CRYPTO_LOCK_BIO);
- if (refs > 0) {
+ if (!CRYPTO_refcount_dec_and_test_zero(&bio->references)) {
return 0;
}
@@ -128,7 +129,7 @@ int BIO_free(BIO *bio) {
}
BIO *BIO_up_ref(BIO *bio) {
- CRYPTO_add(&bio->references, 1, CRYPTO_LOCK_BIO);
+ CRYPTO_refcount_inc(&bio->references);
return bio;
}
@@ -507,7 +508,7 @@ static int bio_read_all(BIO *bio, uint8_t **out, size_t *out_len,
done += n;
if (len < max_len && len - done < kChunkSize / 2) {
len += kChunkSize;
- if (len > max_len) {
+ if (len < kChunkSize || len > max_len) {
len = max_len;
}
uint8_t *new_buf = OPENSSL_realloc(*out, len);
diff --git a/src/crypto/bio/bio_test.cc b/src/crypto/bio/bio_test.cc
index e0193f8..4d7dfe2 100644
--- a/src/crypto/bio/bio_test.cc
+++ b/src/crypto/bio/bio_test.cc
@@ -371,6 +371,9 @@ static bool TestASN1() {
kLargePayloadLen & 0xff};
ScopedOpenSSLBytes large(reinterpret_cast<uint8_t *>(
OPENSSL_malloc(sizeof(kLargePrefix) + kLargePayloadLen)));
+ if (!large) {
+ return false;
+ }
memset(large.get() + sizeof(kLargePrefix), 0, kLargePayloadLen);
memcpy(large.get(), kLargePrefix, sizeof(kLargePrefix));
diff --git a/src/crypto/bio/printf.c b/src/crypto/bio/printf.c
index 3638915..f51b396 100644
--- a/src/crypto/bio/printf.c
+++ b/src/crypto/bio/printf.c
@@ -64,6 +64,7 @@
#include <stdarg.h>
#include <stdio.h>
+#include <openssl/err.h>
#include <openssl/mem.h>
int BIO_printf(BIO *bio, const char *format, ...) {
@@ -94,9 +95,8 @@ int BIO_printf(BIO *bio, const char *format, ...) {
out = OPENSSL_malloc(requested_len + 1);
out_malloced = 1;
if (out == NULL) {
- /* Unclear what can be done in this situation. OpenSSL has historically
- * crashed and that seems better than producing the wrong output. */
- abort();
+ OPENSSL_PUT_ERROR(BIO, BIO_printf, ERR_R_MALLOC_FAILURE);
+ return -1;
}
va_start(args, format);
out_len = vsnprintf(out, requested_len + 1, format, args);
diff --git a/src/crypto/bio/socket_helper.c b/src/crypto/bio/socket_helper.c
index 197c737..b1cdd1a 100644
--- a/src/crypto/bio/socket_helper.c
+++ b/src/crypto/bio/socket_helper.c
@@ -51,7 +51,7 @@ int bio_ip_and_port_to_socket_and_addr(int *out_sock,
ret = getaddrinfo(hostname, port_str, &hint, &result);
if (ret != 0) {
OPENSSL_PUT_ERROR(SYS, getaddrinfo, 0);
- ERR_add_error_data(2, gai_strerror(ret));
+ ERR_add_error_data(1, gai_strerror(ret));
return 0;
}