Fix ssl3_do_write error handling. The functions it calls all pass through <= 0 as error codes, not < 0. Change-Id: I9d0d6b1df0065efc63f2d3a5e7f3497b2c28453a Reviewed-on: https://boringssl-review.googlesource.com/8237 Reviewed-by: Adam Langley <agl@google.com>
diff --git a/ssl/s3_both.c b/ssl/s3_both.c index f5d0c13..f081066 100644 --- a/ssl/s3_both.c +++ b/ssl/s3_both.c
@@ -130,16 +130,16 @@ /* ssl3_do_write sends |ssl->init_buf| in records of type 'type' - * (SSL3_RT_HANDSHAKE or SSL3_RT_CHANGE_CIPHER_SPEC). It returns -1 on error and - * 1 on success. */ + * (SSL3_RT_HANDSHAKE or SSL3_RT_CHANGE_CIPHER_SPEC). It returns 1 on success + * and <= 0 on error. */ int ssl3_do_write(SSL *ssl, int type) { - int n = ssl3_write_bytes(ssl, type, ssl->init_buf->data, ssl->init_num); - if (n < 0) { - return -1; + int ret = ssl3_write_bytes(ssl, type, ssl->init_buf->data, ssl->init_num); + if (ret <= 0) { + return ret; } /* ssl3_write_bytes writes the data in its entirety. */ - assert(n == ssl->init_num); + assert(ret == ssl->init_num); ssl_do_msg_callback(ssl, 1 /* write */, ssl->version, type, ssl->init_buf->data, (size_t)ssl->init_num); ssl->init_num = 0;