Skip to content

Commit

Permalink
Return NULL if we fail to create a BIO in the demos/quicserver
Browse files Browse the repository at this point in the history
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 #21950)
  • Loading branch information
mattcaswell committed Sep 8, 2023
1 parent cdedecd commit 11b7d46
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 16 deletions.
6 changes: 4 additions & 2 deletions demos/guide/quic-client-block.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions demos/guide/quic-client-non-block.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions demos/guide/quic-multi-stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion demos/guide/tls-client-block.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions demos/guide/tls-client-non-block.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions doc/man7/ossl-guide-quic-client-block.pod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions doc/man7/ossl-guide-tls-client-block.pod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions util/quicserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 11b7d46

Please sign in to comment.