From: Matt Caswell Date: Tue, 25 Oct 2016 12:19:59 +0000 (+0100) Subject: Fix some feedback issues for BIO size_t-ify X-Git-Tag: OpenSSL_1_1_1-pre1~3312 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=7bf79e33c94545eb3d67f142ce2dcc974c4dc79b;p=oweals%2Fopenssl.git Fix some feedback issues for BIO size_t-ify Rename some parameters; add some error codes; fix a comment; etc Reviewed-by: Richard Levitte --- diff --git a/crypto/bio/bio_err.c b/crypto/bio/bio_err.c index 68399aa54a..b8cb1ebf13 100644 --- a/crypto/bio/bio_err.c +++ b/crypto/bio/bio_err.c @@ -45,12 +45,14 @@ static ERR_STRING_DATA BIO_str_functs[] = { {ERR_FUNC(BIO_F_BIO_PUTS), "BIO_puts"}, {ERR_FUNC(BIO_F_BIO_READ), "BIO_read"}, {ERR_FUNC(BIO_F_BIO_READ_EX), "BIO_read_ex"}, + {ERR_FUNC(BIO_F_BIO_READ_INTERN), "bio_read_intern"}, {ERR_FUNC(BIO_F_BIO_SOCKET), "BIO_socket"}, {ERR_FUNC(BIO_F_BIO_SOCKET_NBIO), "BIO_socket_nbio"}, {ERR_FUNC(BIO_F_BIO_SOCK_INFO), "BIO_sock_info"}, {ERR_FUNC(BIO_F_BIO_SOCK_INIT), "BIO_sock_init"}, {ERR_FUNC(BIO_F_BIO_WRITE), "BIO_write"}, {ERR_FUNC(BIO_F_BIO_WRITE_EX), "BIO_write_ex"}, + {ERR_FUNC(BIO_F_BIO_WRITE_INTERN), "bio_write_intern"}, {ERR_FUNC(BIO_F_BUFFER_CTRL), "buffer_ctrl"}, {ERR_FUNC(BIO_F_CONN_CTRL), "conn_ctrl"}, {ERR_FUNC(BIO_F_CONN_STATE), "conn_state"}, @@ -82,6 +84,7 @@ static ERR_STRING_DATA BIO_str_reasons[] = { {ERR_REASON(BIO_R_INVALID_ARGUMENT), "invalid argument"}, {ERR_REASON(BIO_R_INVALID_SOCKET), "invalid socket"}, {ERR_REASON(BIO_R_IN_USE), "in use"}, + {ERR_REASON(BIO_R_LENGTH_TOO_LONG), "length too long"}, {ERR_REASON(BIO_R_LISTEN_V6_ONLY), "listen v6 only"}, {ERR_REASON(BIO_R_LOOKUP_RETURNED_NOTHING), "lookup returned nothing"}, {ERR_REASON(BIO_R_MALFORMED_HOST_OR_SERVICE), diff --git a/crypto/bio/bio_lib.c b/crypto/bio/bio_lib.c index b8673adce0..430eac8bb5 100644 --- a/crypto/bio/bio_lib.c +++ b/crypto/bio/bio_lib.c @@ -61,9 +61,6 @@ static long bio_call_callback(BIO *b, int oper, const char *argp, size_t len, ret = b->callback(b, oper, argp, argi, argl, inret); - if (ret > LONG_MAX || ret < LONG_MIN) - return -1; - if (ret >= 0 && (HAS_LEN_OPER(bareoper) || bareoper == BIO_CB_PUTS)) { *processed = (size_t)ret; ret = 1; @@ -246,54 +243,56 @@ int BIO_method_type(const BIO *b) /* * This is essentially the same as BIO_read_ex() except that it allows - * 0 or a -ve value to indicate failure (retryable or not) in the return. This - * is for compatibility with the old style BIO_read(), where existing code may - * make assumptions about the return value that it might get. + * 0 or a negative value to indicate failure (retryable or not) in the return. + * This is for compatibility with the old style BIO_read(), where existing code + * may make assumptions about the return value that it might get. */ -static int bio_read_intern(BIO *b, void *data, size_t datal, size_t *read) +static int bio_read_intern(BIO *b, void *data, size_t dlen, size_t *read) { int ret; if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL)) { - BIOerr(BIO_F_BIO_READ_EX, BIO_R_UNSUPPORTED_METHOD); + BIOerr(BIO_F_BIO_READ_INTERN, BIO_R_UNSUPPORTED_METHOD); return -2; } if ((b->callback != NULL || b->callback_ex != NULL) && - ((ret = (int)bio_call_callback(b, BIO_CB_READ, data, datal, 0, 0L, 1L, + ((ret = (int)bio_call_callback(b, BIO_CB_READ, data, dlen, 0, 0L, 1L, read)) <= 0)) return ret; if (!b->init) { - BIOerr(BIO_F_BIO_READ_EX, BIO_R_UNINITIALIZED); + BIOerr(BIO_F_BIO_READ_INTERN, BIO_R_UNINITIALIZED); return -2; } - ret = b->method->bread(b, data, datal, read); + ret = b->method->bread(b, data, dlen, read); if (ret > 0) b->num_read += (uint64_t)*read; if (b->callback != NULL || b->callback_ex != NULL) ret = (int)bio_call_callback(b, BIO_CB_READ | BIO_CB_RETURN, data, - datal, 0, 0L, ret, read); + dlen, 0, 0L, ret, read); /* Shouldn't happen */ - if (ret > 0 && *read > datal) + if (ret > 0 && *read > dlen) { + BIOerr(BIO_F_BIO_READ_INTERN, ERR_R_INTERNAL_ERROR); return -1; + } return ret; } -int BIO_read(BIO *b, void *data, int datal) +int BIO_read(BIO *b, void *data, int dlen) { size_t read; int ret; - if (datal < 0) + if (dlen < 0) return 0; - ret = bio_read_intern(b, data, (size_t)datal, &read); + ret = bio_read_intern(b, data, (size_t)dlen, &read); if (ret > 0) { /* *read should always be <= outl */ @@ -303,11 +302,11 @@ int BIO_read(BIO *b, void *data, int datal) return ret; } -int BIO_read_ex(BIO *b, void *data, size_t datal, size_t *read) +int BIO_read_ex(BIO *b, void *data, size_t dlen, size_t *read) { int ret; - ret = bio_read_intern(b, data, datal, read); + ret = bio_read_intern(b, data, dlen, read); if (ret > 0) ret = 1; @@ -317,7 +316,7 @@ int BIO_read_ex(BIO *b, void *data, size_t datal, size_t *read) return ret; } -static int bio_write_intern(BIO *b, const void *data, size_t datal, +static int bio_write_intern(BIO *b, const void *data, size_t dlen, size_t *written) { int ret; @@ -326,41 +325,41 @@ static int bio_write_intern(BIO *b, const void *data, size_t datal, return 0; if ((b->method == NULL) || (b->method->bwrite == NULL)) { - BIOerr(BIO_F_BIO_WRITE_EX, BIO_R_UNSUPPORTED_METHOD); + BIOerr(BIO_F_BIO_WRITE_INTERN, BIO_R_UNSUPPORTED_METHOD); return -2; } if ((b->callback != NULL || b->callback_ex != NULL) && - ((ret = (int)bio_call_callback(b, BIO_CB_WRITE, data, datal, 0, 0L, 1L, + ((ret = (int)bio_call_callback(b, BIO_CB_WRITE, data, dlen, 0, 0L, 1L, written)) <= 0)) return ret; if (!b->init) { - BIOerr(BIO_F_BIO_WRITE_EX, BIO_R_UNINITIALIZED); + BIOerr(BIO_F_BIO_WRITE_INTERN, BIO_R_UNINITIALIZED); return -2; } - ret = b->method->bwrite(b, data, datal, written); + ret = b->method->bwrite(b, data, dlen, written); if (ret > 0) b->num_write += (uint64_t)*written; if (b->callback != NULL || b->callback_ex != NULL) ret = (int)bio_call_callback(b, BIO_CB_WRITE | BIO_CB_RETURN, data, - datal, 0, 0L, ret, written); + dlen, 0, 0L, ret, written); return ret; } -int BIO_write(BIO *b, const void *data, int datal) +int BIO_write(BIO *b, const void *data, int dlen) { size_t written; int ret; - if (datal < 0) + if (dlen < 0) return 0; - ret = bio_write_intern(b, data, (size_t)datal, &written); + ret = bio_write_intern(b, data, (size_t)dlen, &written); if (ret > 0) { /* *written should always be <= inl */ @@ -370,11 +369,11 @@ int BIO_write(BIO *b, const void *data, int datal) return ret; } -int BIO_write_ex(BIO *b, const void *data, size_t datal, size_t *written) +int BIO_write_ex(BIO *b, const void *data, size_t dlen, size_t *written) { int ret; - ret = bio_write_intern(b, data, datal, written); + ret = bio_write_intern(b, data, dlen, written); if (ret > 0) ret = 1; @@ -418,10 +417,12 @@ int BIO_puts(BIO *b, const char *in) 0L, ret, &written); if (ret > 0) { - if (written > INT_MAX) + if (written > INT_MAX) { + BIOerr(BIO_F_BIO_PUTS, BIO_R_LENGTH_TOO_LONG); ret = -1; - else + } else { ret = (int)written; + } } return ret; diff --git a/include/openssl/bio.h b/include/openssl/bio.h index a3c5062f21..4b807191ef 100644 --- a/include/openssl/bio.h +++ b/include/openssl/bio.h @@ -551,11 +551,11 @@ void BIO_set_shutdown(BIO *a, int shut); int BIO_get_shutdown(BIO *a); void BIO_vfree(BIO *a); int BIO_up_ref(BIO *a); -int BIO_read(BIO *b, void *data, int datal); -int BIO_read_ex(BIO *b, void *data, size_t datal, size_t *read); +int BIO_read(BIO *b, void *data, int dlen); +int BIO_read_ex(BIO *b, void *data, size_t dlen, size_t *read); int BIO_gets(BIO *bp, char *buf, int size); -int BIO_write(BIO *b, const void *data, int datal); -int BIO_write_ex(BIO *b, const void *data, size_t datal, size_t *written); +int BIO_write(BIO *b, const void *data, int dlen); +int BIO_write_ex(BIO *b, const void *data, size_t dlen, size_t *written); int BIO_puts(BIO *bp, const char *buf); int BIO_indent(BIO *b, int indent, int max); long BIO_ctrl(BIO *bp, int cmd, long larg, void *parg); @@ -811,12 +811,14 @@ int ERR_load_BIO_strings(void); # define BIO_F_BIO_PUTS 110 # define BIO_F_BIO_READ 111 # define BIO_F_BIO_READ_EX 105 +# define BIO_F_BIO_READ_INTERN 120 # define BIO_F_BIO_SOCKET 140 # define BIO_F_BIO_SOCKET_NBIO 142 # define BIO_F_BIO_SOCK_INFO 141 # define BIO_F_BIO_SOCK_INIT 112 # define BIO_F_BIO_WRITE 113 # define BIO_F_BIO_WRITE_EX 119 +# define BIO_F_BIO_WRITE_INTERN 128 # define BIO_F_BUFFER_CTRL 114 # define BIO_F_CONN_CTRL 127 # define BIO_F_CONN_STATE 115 @@ -842,6 +844,7 @@ int ERR_load_BIO_strings(void); # define BIO_R_INVALID_ARGUMENT 125 # define BIO_R_INVALID_SOCKET 135 # define BIO_R_IN_USE 123 +# define BIO_R_LENGTH_TOO_LONG 102 # define BIO_R_LISTEN_V6_ONLY 136 # define BIO_R_LOOKUP_RETURNED_NOTHING 142 # define BIO_R_MALFORMED_HOST_OR_SERVICE 130