summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiels Dossche <niels.dossche@ugent.be>2024-10-28 16:34:55 +0100
committerTomas Mraz <tomas@openssl.org>2025-01-02 14:06:51 +0100
commit32476957ead4151dceaf873306fc7e79cd262812 (patch)
treed8eefcef5c75f61333800075a1362ea9c081c569
parentcore_namemap.c: Use OPENSSL_STRING instead of defining STRING type (diff)
downloadopenssl-32476957ead4151dceaf873306fc7e79cd262812.tar.xz
openssl-32476957ead4151dceaf873306fc7e79cd262812.zip
Fix potential memory leak in BIO_get_accept_socket()
When BIO_parse_hostserv() fails it may still have allocated memory, yet this memory is not freed. Fix it by jumping to the err label. Reviewed-by: Viktor Dukhovni <viktor@openssl.org> Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/25817)
-rw-r--r--crypto/bio/bio_addr.c7
-rw-r--r--crypto/bio/bio_sock.c2
2 files changed, 7 insertions, 2 deletions
diff --git a/crypto/bio/bio_addr.c b/crypto/bio/bio_addr.c
index 4b2cef6936..568c0b4a1f 100644
--- a/crypto/bio/bio_addr.c
+++ b/crypto/bio/bio_addr.c
@@ -571,8 +571,13 @@ int BIO_parse_hostserv(const char *hostserv, char **host, char **service,
*service = NULL;
} else {
*service = OPENSSL_strndup(p, pl);
- if (*service == NULL)
+ if (*service == NULL) {
+ if (h != NULL && host != NULL) {
+ OPENSSL_free(*host);
+ *host = NULL;
+ }
return 0;
+ }
}
}
diff --git a/crypto/bio/bio_sock.c b/crypto/bio/bio_sock.c
index 3ea122e2b9..22dbf38b00 100644
--- a/crypto/bio/bio_sock.c
+++ b/crypto/bio/bio_sock.c
@@ -259,7 +259,7 @@ int BIO_get_accept_socket(char *host, int bind_mode)
return INVALID_SOCKET;
if (BIO_sock_init() != 1)
- return INVALID_SOCKET;
+ goto err;
if (BIO_lookup(h, p, BIO_LOOKUP_SERVER, AF_UNSPEC, SOCK_STREAM, &res) != 0)
goto err;