From: Matt Caswell Date: Wed, 6 Sep 2023 11:36:43 +0000 (+0100) Subject: Return NULL if we fail to create a BIO in the demos/quicserver X-Git-Tag: openssl-3.2.0-alpha2~115 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=11b7d46fa7e2684e0ad0f12a7806163dba99983d;p=thirdparty%2Fopenssl.git Return NULL if we fail to create a BIO in the demos/quicserver Strictly speaking the previous code was still correct since BIO_set_fd is tolerant of a NULL BIO. But this way is more clear. Reviewed-by: Tomas Mraz Reviewed-by: Hugo Landau (Merged from https://github.com/openssl/openssl/pull/21950) --- diff --git a/demos/guide/quic-client-block.c b/demos/guide/quic-client-block.c index 2c177b4f187..e6cabfef260 100644 --- a/demos/guide/quic-client-block.c +++ b/demos/guide/quic-client-block.c @@ -89,10 +89,12 @@ static BIO *create_socket_bio(const char *hostname, const char *port, if (sock == -1) return NULL; - /* Create a BIO to wrap the socket*/ + /* Create a BIO to wrap the socket */ bio = BIO_new(BIO_s_datagram()); - if (bio == NULL) + if (bio == NULL) { BIO_closesocket(sock); + return NULL; + } /* * Associate the newly created BIO with the underlying socket. By diff --git a/demos/guide/quic-client-non-block.c b/demos/guide/quic-client-non-block.c index e1735c0c5d2..61d339c79ca 100644 --- a/demos/guide/quic-client-non-block.c +++ b/demos/guide/quic-client-non-block.c @@ -90,10 +90,12 @@ static BIO *create_socket_bio(const char *hostname, const char *port, if (sock == -1) return NULL; - /* Create a BIO to wrap the socket*/ + /* Create a BIO to wrap the socket */ bio = BIO_new(BIO_s_datagram()); - if (bio == NULL) + if (bio == NULL) { BIO_closesocket(sock); + return NULL; + } /* * Associate the newly created BIO with the underlying socket. By diff --git a/demos/guide/quic-multi-stream.c b/demos/guide/quic-multi-stream.c index 8b6567aa837..56db5a98a8b 100644 --- a/demos/guide/quic-multi-stream.c +++ b/demos/guide/quic-multi-stream.c @@ -90,11 +90,12 @@ static BIO *create_socket_bio(const char *hostname, const char *port, if (sock == -1) return NULL; - /* Create a BIO to wrap the socket*/ + /* Create a BIO to wrap the socket */ bio = BIO_new(BIO_s_datagram()); - if (bio == NULL) + if (bio == NULL) { BIO_closesocket(sock); - + return NULL; + } /* * Associate the newly created BIO with the underlying socket. By * passing BIO_CLOSE here the socket will be automatically closed when diff --git a/demos/guide/tls-client-block.c b/demos/guide/tls-client-block.c index b2d2a89dd13..75ce7ebcc24 100644 --- a/demos/guide/tls-client-block.c +++ b/demos/guide/tls-client-block.c @@ -76,8 +76,10 @@ static BIO *create_socket_bio(const char *hostname, const char *port) /* Create a BIO to wrap the socket*/ bio = BIO_new(BIO_s_socket()); - if (bio == NULL) + if (bio == NULL) { BIO_closesocket(sock); + return NULL; + } /* * Associate the newly created BIO with the underlying socket. By diff --git a/demos/guide/tls-client-non-block.c b/demos/guide/tls-client-non-block.c index dc6ee4dce89..14448c96852 100644 --- a/demos/guide/tls-client-non-block.c +++ b/demos/guide/tls-client-non-block.c @@ -81,10 +81,12 @@ static BIO *create_socket_bio(const char *hostname, const char *port) if (sock == -1) return NULL; - /* Create a BIO to wrap the socket*/ + /* Create a BIO to wrap the socket */ bio = BIO_new(BIO_s_socket()); - if (bio == NULL) + if (bio == NULL) { BIO_closesocket(sock); + return NULL; + } /* * Associate the newly created BIO with the underlying socket. By diff --git a/doc/man7/ossl-guide-quic-client-block.pod b/doc/man7/ossl-guide-quic-client-block.pod index 4cf8bdd3b82..fc8912086da 100644 --- a/doc/man7/ossl-guide-quic-client-block.pod +++ b/doc/man7/ossl-guide-quic-client-block.pod @@ -165,10 +165,12 @@ associate it with a BIO object: BIO *bio; - /* Create a BIO to wrap the socket*/ + /* Create a BIO to wrap the socket */ bio = BIO_new(BIO_s_datagram()); - if (bio == NULL) + if (bio == NULL) { BIO_closesocket(sock); + return NULL; + } /* * Associate the newly created BIO with the underlying socket. By diff --git a/doc/man7/ossl-guide-tls-client-block.pod b/doc/man7/ossl-guide-tls-client-block.pod index 236553fafd5..865a5353b3f 100644 --- a/doc/man7/ossl-guide-tls-client-block.pod +++ b/doc/man7/ossl-guide-tls-client-block.pod @@ -222,10 +222,12 @@ BIO object: BIO *bio; - /* Create a BIO to wrap the socket*/ + /* Create a BIO to wrap the socket */ bio = BIO_new(BIO_s_socket()); - if (bio == NULL) + if (bio == NULL) { BIO_closesocket(sock); + return NULL; + } /* * Associate the newly created BIO with the underlying socket. By diff --git a/util/quicserver.c b/util/quicserver.c index 5a51b240ffd..fd9f9399bd6 100644 --- a/util/quicserver.c +++ b/util/quicserver.c @@ -113,10 +113,12 @@ static BIO *create_dgram_bio(int family, const char *hostname, const char *port) if (sock == -1) return NULL; - /* Create a BIO to wrap the socket*/ + /* Create a BIO to wrap the socket */ bio = BIO_new(BIO_s_datagram()); - if (bio == NULL) + if (bio == NULL) { BIO_closesocket(sock); + return NULL; + } /* * Associate the newly created BIO with the underlying socket. By