diff --git a/crypto/bio/connect.c b/crypto/bio/connect.c index 2ed2def1..cc28ef87 100644 --- a/crypto/bio/connect.c +++ b/crypto/bio/connect.c @@ -445,9 +445,9 @@ static long conn_ctrl(BIO *bio, int cmd, long num, void *ptr) { if (ip != NULL) { *ip = bio->num; } - ret = 1; + ret = bio->num; } else { - ret = 0; + ret = -1; } break; case BIO_CTRL_GET_CLOSE: diff --git a/crypto/bio/fd.c b/crypto/bio/fd.c index 0b5baca9..0b3484c9 100644 --- a/crypto/bio/fd.c +++ b/crypto/bio/fd.c @@ -208,9 +208,9 @@ static long fd_ctrl(BIO *b, int cmd, long num, void *ptr) { if (ip != NULL) { *ip = b->num; } - return 1; + return b->num; } else { - ret = 0; + ret = -1; } break; case BIO_CTRL_GET_CLOSE: diff --git a/include/openssl/bio.h b/include/openssl/bio.h index 04e37907..481b97ea 100644 --- a/include/openssl/bio.h +++ b/include/openssl/bio.h @@ -444,8 +444,9 @@ OPENSSL_EXPORT BIO *BIO_new_fd(int fd, int close_flag); * or zero on error. */ OPENSSL_EXPORT int BIO_set_fd(BIO *bio, int fd, int close_flag); -/* BIO_get_fd sets |*out_fd| to the file descriptor currently in use by |bio|. - * It returns one on success and zero on error. */ +/* BIO_get_fd returns the file descriptor currently in use by |bio| or -1 if + * |bio| does not wrap a file descriptor. If there is a file descriptor and + * |out_fd| is not NULL, it also sets |*out_fd| to the file descriptor. */ OPENSSL_EXPORT int BIO_get_fd(BIO *bio, int *out_fd); diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c index 25d65c11..66867ba4 100644 --- a/ssl/ssl_lib.c +++ b/ssl/ssl_lib.c @@ -1121,7 +1121,7 @@ int SSL_set_wfd(SSL *s, int fd) { BIO *bio = NULL; if (s->rbio == NULL || BIO_method_type(s->rbio) != BIO_TYPE_FD || - (int)BIO_get_fd(s->rbio, NULL) != fd) { + BIO_get_fd(s->rbio, NULL) != fd) { bio = BIO_new(BIO_s_fd()); if (bio == NULL) { @@ -1145,7 +1145,7 @@ int SSL_set_rfd(SSL *s, int fd) { BIO *bio = NULL; if (s->wbio == NULL || BIO_method_type(s->wbio) != BIO_TYPE_FD || - (int)BIO_get_fd(s->wbio, NULL) != fd) { + BIO_get_fd(s->wbio, NULL) != fd) { bio = BIO_new(BIO_s_fd()); if (bio == NULL) {