From: Richard Levitte Date: Fri, 8 Sep 2023 06:20:02 +0000 (+0200) Subject: Fix test_quic_multistream to allow multiple concurrent tests X-Git-Tag: openssl-3.2.0-alpha2~107 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=84f371a130dbe7a46595fbabd274f152a0e6385f;p=thirdparty%2Fopenssl.git Fix test_quic_multistream to allow multiple concurrent tests The server port was hard coded to 8186. That could make for some "interesting" effects if two instances of this same test was running on the same machine. This change binds the server interface with port 0, and captures the resulting random port. Reviewed-by: Tomas Mraz Reviewed-by: Paul Dale Reviewed-by: Hugo Landau (Merged from https://github.com/openssl/openssl/pull/22025) --- diff --git a/test/quic_multistream_test.c b/test/quic_multistream_test.c index e8a145726cd..bc0ae12cdb1 100644 --- a/test/quic_multistream_test.c +++ b/test/quic_multistream_test.c @@ -48,7 +48,11 @@ DEFINE_LHASH_OF_EX(STREAM_INFO); struct helper { int s_fd; BIO *s_net_bio, *s_net_bio_own, *s_qtf_wbio, *s_qtf_wbio_own; + /* The BIO_ADDR used for BIO_bind() */ + BIO_ADDR *s_net_bio_orig_addr; + /* The resulting address, which is the one to connect to */ BIO_ADDR *s_net_bio_addr; + /* * When doing a blocking mode test run, s_priv always points to the TSERVER * and s is NULL when the main thread should not be touching s_priv. @@ -633,6 +637,8 @@ static void helper_cleanup(struct helper *h) BIO_ADDR_free(h->s_net_bio_addr); h->s_net_bio_addr = NULL; + BIO_ADDR_free(h->s_net_bio_orig_addr); + h->s_net_bio_orig_addr = NULL; SSL_CTX_free(h->c_ctx); h->c_ctx = NULL; @@ -651,9 +657,9 @@ static void helper_cleanup(struct helper *h) static int helper_init(struct helper *h, int free_order, int blocking, int need_injector) { - short port = 8186; struct in_addr ina = {0}; QUIC_TSERVER_ARGS s_args = {0}; + union BIO_sock_info_u info; memset(h, 0, sizeof(*h)); h->c_fd = -1; @@ -683,14 +689,19 @@ static int helper_init(struct helper *h, int free_order, int blocking, if (!TEST_true(BIO_socket_nbio(h->s_fd, 1))) goto err; - if (!TEST_ptr(h->s_net_bio_addr = BIO_ADDR_new())) + if (!TEST_ptr(h->s_net_bio_orig_addr = BIO_ADDR_new()) + || !TEST_ptr(h->s_net_bio_addr = BIO_ADDR_new())) + goto err; + + if (!TEST_true(BIO_ADDR_rawmake(h->s_net_bio_orig_addr, AF_INET, + &ina, sizeof(ina), 0))) goto err; - if (!TEST_true(BIO_ADDR_rawmake(h->s_net_bio_addr, AF_INET, &ina, sizeof(ina), - htons(port)))) + if (!TEST_true(BIO_bind(h->s_fd, h->s_net_bio_orig_addr, 0))) goto err; - if (!TEST_true(BIO_bind(h->s_fd, h->s_net_bio_addr, 0))) + info.addr = h->s_net_bio_addr; + if (!TEST_true(BIO_sock_info(h->s_fd, BIO_SOCK_INFO_ADDRESS, &info))) goto err; if (!TEST_int_gt(BIO_ADDR_rawport(h->s_net_bio_addr), 0))