From: Bodo Möller Date: Fri, 10 Mar 2000 21:44:38 +0000 (+0000) Subject: Use signed types where necessary, and add missing functionality X-Git-Tag: OpenSSL_0_9_5a-beta1~67 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=4991d07cf3094e73a4eaa97d527844f8c2a28a77;p=oweals%2Fopenssl.git Use signed types where necessary, and add missing functionality to make SSL_nread0 work. --- diff --git a/crypto/bio/bss_bio.c b/crypto/bio/bss_bio.c index cff55bfa89..1e2d7491f2 100644 --- a/crypto/bio/bss_bio.c +++ b/crypto/bio/bss_bio.c @@ -16,12 +16,17 @@ #include #include #include -#include #include #include +#include #include +#include "openssl/e_os.h" +#ifndef SSIZE_MAX +# define SSIZE_MAX INT_MAX +#endif + static int bio_new(BIO *bio); static int bio_free(BIO *bio); static int bio_read(BIO *bio, char *buf, int size); @@ -209,7 +214,7 @@ static int bio_read(BIO *bio, char *buf, int size_) static ssize_t bio_nread0(BIO *bio, char **buf) { struct bio_bio_st *b, *peer_b; - size_t num; + ssize_t num; BIO_clear_retry_flags(bio); @@ -244,15 +249,20 @@ static ssize_t bio_nread0(BIO *bio, char **buf) return num; } -static ssize_t bio_nread(BIO *bio, char **buf, size_t num) +static ssize_t bio_nread(BIO *bio, char **buf, size_t num_) { struct bio_bio_st *b, *peer_b; - size_t available; + ssize_t num, available; + + if (num_ > SSIZE_MAX) + num = SSIZE_MAX; + else + num = (ssize_t)num_; available = bio_nread0(bio, buf); if (num > available) num = available; - if (num == 0) + if (num <= 0) return num; b = bio->ptr; @@ -352,7 +362,7 @@ static int bio_write(BIO *bio, char *buf, int num_) * (example usage: bio_nwrite0(), write to buffer, bio_nwrite() * or just bio_nwrite(), write to buffer) */ -static size_t bio_nwrite0(BIO *bio, char **buf) +static ssize_t bio_nwrite0(BIO *bio, char **buf) { struct bio_bio_st *b; size_t num; @@ -400,15 +410,20 @@ static size_t bio_nwrite0(BIO *bio, char **buf) return num; } -static size_t bio_nwrite(BIO *bio, char **buf, size_t num) +static ssize_t bio_nwrite(BIO *bio, char **buf, size_t num_) { struct bio_bio_st *b; - size_t space; + ssize_t num, space; + + if (num_ > SSIZE_MAX) + num = SSIZE_MAX; + else + num = (ssize_t)num_; space = bio_nwrite0(bio, buf); if (num > space) num = space; - if (num == 0) + if (num <= 0) return num; b = bio->ptr; assert(b != NULL); @@ -510,6 +525,11 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) ret = 1; break; + case BIO_C_NREAD0: + /* prepare for non-copying read */ + ret = (long) bio_nread0(bio, ptr); + break; + case BIO_C_NREAD: /* non-copying read */ ret = (long) bio_nread(bio, ptr, (size_t) num);