diff options
author | David Benjamin <davidben@google.com> | 2016-03-07 03:26:52 +0300 |
---|---|---|
committer | David Benjamin <davidben@google.com> | 2016-03-07 21:19:12 +0300 |
commit | 22ce9b2d08a52e399bf2ab86851952d727be034d (patch) | |
tree | 75f68ef2ea91c766e6ca2bd9cc1aaa1fdf87c574 /include/openssl/bio.h | |
parent | 66b2fe8e0273d1f6cca5db95d4ac3979621dc4ce (diff) |
SSL_set_fd should create socket BIOs, not fd BIOs.
In OpenSSL, they create socket BIOs. The distinction isn't important on UNIX.
On Windows, file descriptors are provided by the C runtime, while sockets must
use separate recv and send APIs. Document how these APIs are intended to work.
Also add a TODO to resolve the SOCKET vs int thing. This code assumes that
Windows HANDLEs only use the bottom 32 bits of precision. (Which is currently
true and probably will continue to be true for the foreseeable future[*], but
it'd be nice to do this right.)
Thanks to Gisle Vanem and Daniel Stenberg for reporting the bug.
[*] Both so Windows can continue to run 32-bit programs and because of all the
random UNIX software, like OpenSSL and ourselves, out there which happily
assumes sockets are ints.
Change-Id: I67408c218572228cb1a7d269892513cda4261c82
Reviewed-on: https://boringssl-review.googlesource.com/7333
Reviewed-by: David Benjamin <davidben@google.com>
Diffstat (limited to 'include/openssl/bio.h')
-rw-r--r-- | include/openssl/bio.h | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/include/openssl/bio.h b/include/openssl/bio.h index a2f0d83e..75afada9 100644 --- a/include/openssl/bio.h +++ b/include/openssl/bio.h @@ -435,12 +435,18 @@ OPENSSL_EXPORT BIO *BIO_new_fd(int fd, int close_flag); /* BIO_set_fd sets the file descriptor of |bio| to |fd|. If |close_flag| is * non-zero then |fd| will be closed when |bio| is. It returns one on success - * or zero on error. */ + * or zero on error. + * + * This function may also be used with socket BIOs (see |BIO_s_socket| and + * |BIO_new_socket|). */ OPENSSL_EXPORT int BIO_set_fd(BIO *bio, int fd, int close_flag); /* 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. */ + * |out_fd| is not NULL, it also sets |*out_fd| to the file descriptor. + * + * This function may also be used with socket BIOs (see |BIO_s_socket| and + * |BIO_new_socket|). */ OPENSSL_EXPORT int BIO_get_fd(BIO *bio, int *out_fd); @@ -520,7 +526,17 @@ OPENSSL_EXPORT int BIO_set_read_buffer_size(BIO *bio, int buffer_size); OPENSSL_EXPORT int BIO_set_write_buffer_size(BIO *bio, int buffer_size); -/* Socket BIOs. */ +/* Socket BIOs. + * + * Socket BIOs behave like file descriptor BIOs but wrap the system's |recv| + * and |send| functions. This is relevant for Windows systems where file + * descriptors, provided by C runtime for use with |read| and |write|, are not + * interchangeable with sockets. + * + * Socket BIOs may be used with |BIO_set_fd| and |BIO_get_fd|. + * + * TODO(davidben): Add separate APIs and fix the internals to use |SOCKET|s + * around rather than rely on int casts. */ OPENSSL_EXPORT const BIO_METHOD *BIO_s_socket(void); |