]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: ssl_sock: fix possible memory leak on OOM
authorWilly Tarreau <w@1wt.eu>
Mon, 21 Aug 2023 06:45:35 +0000 (08:45 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 25 Aug 2023 12:32:50 +0000 (14:32 +0200)
That's the classical realloc() issue: if it returns NULL, the old area
is not freed but we erase the pointer. It was brought by commit e18d4e828
("BUG/MEDIUM: ssl: backend TLS resumption with sni and TLSv1.3"), and
should be backported where this commit was backported.

src/ssl_sock.c

index 6453265a34ebd91de98eb49f27409789208ad64f..922c24cebe1d69ce1eb8bd60a72e0277223a52d0 100644 (file)
@@ -4280,6 +4280,8 @@ static int ssl_sess_new_srv_cb(SSL *ssl, SSL_SESSION *sess)
                        ptr = s->ssl_ctx.reused_sess[tid].ptr;
                } else {
                        ptr = realloc(s->ssl_ctx.reused_sess[tid].ptr, len);
+                       if (!ptr)
+                               free(s->ssl_ctx.reused_sess[tid].ptr);
                        s->ssl_ctx.reused_sess[tid].ptr = ptr;
                        s->ssl_ctx.reused_sess[tid].allocated_size = len;
                }