]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: ssl_sock: add check for ha_meth
authoreaglegai <eaglegai@163.com>
Fri, 26 May 2023 08:42:47 +0000 (16:42 +0800)
committerWilly Tarreau <w@1wt.eu>
Fri, 26 May 2023 10:07:43 +0000 (12:07 +0200)
in __ssl_sock_init, BIO_meth_new may failed and return NULL if
OPENSSL_zalloc failed.  in this case, ha_meth  will be NULL, and then
crash happens in  BIO_meth_set_write.  So, we add a check for ha_meth.

src/ssl_sock.c

index e637b0423a9af81111a9823152ee51eca46eb728..ff0db9d1a1c2af5ead244dd18dcbed9cf329190d 100644 (file)
@@ -7561,13 +7561,15 @@ static void __ssl_sock_init(void)
        ERR_load_SSL_strings();
 #endif
        ha_meth = BIO_meth_new(0x666, "ha methods");
-       BIO_meth_set_write(ha_meth, ha_ssl_write);
-       BIO_meth_set_read(ha_meth, ha_ssl_read);
-       BIO_meth_set_ctrl(ha_meth, ha_ssl_ctrl);
-       BIO_meth_set_create(ha_meth, ha_ssl_new);
-       BIO_meth_set_destroy(ha_meth, ha_ssl_free);
-       BIO_meth_set_puts(ha_meth, ha_ssl_puts);
-       BIO_meth_set_gets(ha_meth, ha_ssl_gets);
+       if (ha_meth != NULL) {
+               BIO_meth_set_write(ha_meth, ha_ssl_write);
+               BIO_meth_set_read(ha_meth, ha_ssl_read);
+               BIO_meth_set_ctrl(ha_meth, ha_ssl_ctrl);
+               BIO_meth_set_create(ha_meth, ha_ssl_new);
+               BIO_meth_set_destroy(ha_meth, ha_ssl_free);
+               BIO_meth_set_puts(ha_meth, ha_ssl_puts);
+               BIO_meth_set_gets(ha_meth, ha_ssl_gets);
+       }
 
        HA_SPIN_INIT(&ckch_lock);