]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix potential memory leak in BIO_get_accept_socket()
authorNiels Dossche <niels.dossche@ugent.be>
Mon, 28 Oct 2024 15:34:55 +0000 (16:34 +0100)
committerTomas Mraz <tomas@openssl.org>
Thu, 2 Jan 2025 13:10:14 +0000 (14:10 +0100)
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)

(cherry picked from commit 32476957ead4151dceaf873306fc7e79cd262812)

crypto/bio/bio_addr.c
crypto/bio/bio_sock.c

index 77cb4395743ee8657e4547bf24c2349f6bfb1825..5852e9fe9e79167e584fd696aafb6e03edd71cda 100644 (file)
@@ -547,8 +547,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;
+                }
                 goto memerr;
+            }
         }
     }
 
index 12e6a68e3a25d82f17def02e4b9d6544318b471b..bb536379dc56fc3d357b5bed5092f56474f68599 100644 (file)
@@ -222,7 +222,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;