Further fix in bio_dgram_test for BIO_s_dgram_mem()
authorMatt Caswell <matt@openssl.org>
Tue, 12 Sep 2023 09:39:51 +0000 (10:39 +0100)
committerMatt Caswell <matt@openssl.org>
Wed, 13 Sep 2023 10:53:13 +0000 (11:53 +0100)
When setting an explicit buffer size using BIO_s_dgram_mem() make sure we
take into account the size of the header (which may be large on NonStop)

Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22058)

test/bio_dgram_test.c

index 70157493f971ae42a33982d0d5c2f9e4fa96f3f6..aca016ca95b07f50ba63b2f5b8999f18eb568c44 100644 (file)
@@ -12,6 +12,7 @@
 #include <openssl/rand.h>
 #include "testutil.h"
 #include "internal/sockets.h"
+#include "internal/bio_addr.h"
 
 #if !defined(OPENSSL_NO_DGRAM) && !defined(OPENSSL_NO_SOCK)
 
@@ -519,14 +520,24 @@ static int test_bio_dgram_pair(int idx)
     } else {
         if (!TEST_ptr(bio1 = bio2 = BIO_new(BIO_s_dgram_mem())))
             goto err;
-        if (idx == 1 && !TEST_true(BIO_set_write_buf_size(bio1, 20 * 1024)))
-            goto err;
     }
 
     mtu1 = BIO_dgram_get_mtu(bio1);
     if (!TEST_int_ge(mtu1, 1280))
         goto err;
 
+    if (idx == 1) {
+        size_t bufsz;
+
+        /*
+         * Assume the header contains 2 BIO_ADDR structures and a length. We
+         * set a buffer big enough for 9 full sized datagrams.
+         */
+        bufsz = 9 * (mtu1 + (sizeof(BIO_ADDR) * 2) + sizeof(size_t));
+        if (!TEST_true(BIO_set_write_buf_size(bio1, bufsz)))
+            goto err;
+    }
+
     mtu2 = BIO_dgram_get_mtu(bio2);
     if (!TEST_int_ge(mtu2, 1280))
         goto err;