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 <tomas@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/21950)
This commit is contained in:
Matt Caswell 2023-09-06 12:36:43 +01:00
parent cdedecd503
commit 11b7d46fa7
8 changed files with 31 additions and 16 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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