diff options
Diffstat (limited to 'src/lib/libcrypto/bio/bss_bio.c')
-rw-r--r-- | src/lib/libcrypto/bio/bss_bio.c | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/src/lib/libcrypto/bio/bss_bio.c b/src/lib/libcrypto/bio/bss_bio.c index 0d0f9356f7..1e2d7491f2 100644 --- a/src/lib/libcrypto/bio/bss_bio.c +++ b/src/lib/libcrypto/bio/bss_bio.c | |||
@@ -19,8 +19,14 @@ | |||
19 | 19 | ||
20 | #include <openssl/bio.h> | 20 | #include <openssl/bio.h> |
21 | #include <openssl/err.h> | 21 | #include <openssl/err.h> |
22 | #include <openssl/err.h> | ||
22 | #include <openssl/crypto.h> | 23 | #include <openssl/crypto.h> |
23 | 24 | ||
25 | #include "openssl/e_os.h" | ||
26 | #ifndef SSIZE_MAX | ||
27 | # define SSIZE_MAX INT_MAX | ||
28 | #endif | ||
29 | |||
24 | static int bio_new(BIO *bio); | 30 | static int bio_new(BIO *bio); |
25 | static int bio_free(BIO *bio); | 31 | static int bio_free(BIO *bio); |
26 | static int bio_read(BIO *bio, char *buf, int size); | 32 | static int bio_read(BIO *bio, char *buf, int size); |
@@ -205,10 +211,10 @@ static int bio_read(BIO *bio, char *buf, int size_) | |||
205 | */ | 211 | */ |
206 | /* WARNING: The non-copying interface is largely untested as of yet | 212 | /* WARNING: The non-copying interface is largely untested as of yet |
207 | * and may contain bugs. */ | 213 | * and may contain bugs. */ |
208 | static size_t bio_nread0(BIO *bio, char **buf) | 214 | static ssize_t bio_nread0(BIO *bio, char **buf) |
209 | { | 215 | { |
210 | struct bio_bio_st *b, *peer_b; | 216 | struct bio_bio_st *b, *peer_b; |
211 | size_t num; | 217 | ssize_t num; |
212 | 218 | ||
213 | BIO_clear_retry_flags(bio); | 219 | BIO_clear_retry_flags(bio); |
214 | 220 | ||
@@ -243,15 +249,20 @@ static size_t bio_nread0(BIO *bio, char **buf) | |||
243 | return num; | 249 | return num; |
244 | } | 250 | } |
245 | 251 | ||
246 | static size_t bio_nread(BIO *bio, char **buf, size_t num) | 252 | static ssize_t bio_nread(BIO *bio, char **buf, size_t num_) |
247 | { | 253 | { |
248 | struct bio_bio_st *b, *peer_b; | 254 | struct bio_bio_st *b, *peer_b; |
249 | size_t available; | 255 | ssize_t num, available; |
256 | |||
257 | if (num_ > SSIZE_MAX) | ||
258 | num = SSIZE_MAX; | ||
259 | else | ||
260 | num = (ssize_t)num_; | ||
250 | 261 | ||
251 | available = bio_nread0(bio, buf); | 262 | available = bio_nread0(bio, buf); |
252 | if (num > available) | 263 | if (num > available) |
253 | num = available; | 264 | num = available; |
254 | if (num == 0) | 265 | if (num <= 0) |
255 | return num; | 266 | return num; |
256 | 267 | ||
257 | b = bio->ptr; | 268 | b = bio->ptr; |
@@ -351,7 +362,7 @@ static int bio_write(BIO *bio, char *buf, int num_) | |||
351 | * (example usage: bio_nwrite0(), write to buffer, bio_nwrite() | 362 | * (example usage: bio_nwrite0(), write to buffer, bio_nwrite() |
352 | * or just bio_nwrite(), write to buffer) | 363 | * or just bio_nwrite(), write to buffer) |
353 | */ | 364 | */ |
354 | static size_t bio_nwrite0(BIO *bio, char **buf) | 365 | static ssize_t bio_nwrite0(BIO *bio, char **buf) |
355 | { | 366 | { |
356 | struct bio_bio_st *b; | 367 | struct bio_bio_st *b; |
357 | size_t num; | 368 | size_t num; |
@@ -399,15 +410,20 @@ static size_t bio_nwrite0(BIO *bio, char **buf) | |||
399 | return num; | 410 | return num; |
400 | } | 411 | } |
401 | 412 | ||
402 | static size_t bio_nwrite(BIO *bio, char **buf, size_t num) | 413 | static ssize_t bio_nwrite(BIO *bio, char **buf, size_t num_) |
403 | { | 414 | { |
404 | struct bio_bio_st *b; | 415 | struct bio_bio_st *b; |
405 | size_t space; | 416 | ssize_t num, space; |
417 | |||
418 | if (num_ > SSIZE_MAX) | ||
419 | num = SSIZE_MAX; | ||
420 | else | ||
421 | num = (ssize_t)num_; | ||
406 | 422 | ||
407 | space = bio_nwrite0(bio, buf); | 423 | space = bio_nwrite0(bio, buf); |
408 | if (num > space) | 424 | if (num > space) |
409 | num = space; | 425 | num = space; |
410 | if (num == 0) | 426 | if (num <= 0) |
411 | return num; | 427 | return num; |
412 | b = bio->ptr; | 428 | b = bio->ptr; |
413 | assert(b != NULL); | 429 | assert(b != NULL); |
@@ -509,6 +525,11 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) | |||
509 | ret = 1; | 525 | ret = 1; |
510 | break; | 526 | break; |
511 | 527 | ||
528 | case BIO_C_NREAD0: | ||
529 | /* prepare for non-copying read */ | ||
530 | ret = (long) bio_nread0(bio, ptr); | ||
531 | break; | ||
532 | |||
512 | case BIO_C_NREAD: | 533 | case BIO_C_NREAD: |
513 | /* non-copying read */ | 534 | /* non-copying read */ |
514 | ret = (long) bio_nread(bio, ptr, (size_t) num); | 535 | ret = (long) bio_nread(bio, ptr, (size_t) num); |