Skip to content

Commit

Permalink
Fix the BIO_addr test
Browse files Browse the repository at this point in the history
The BIO_addr test is failing on non-stop. The length of the data is larger
than the size we have allocated for it. We dynamically allocate instead.

Fixes #22218

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #22294)
  • Loading branch information
mattcaswell authored and t8m committed Oct 9, 2023
1 parent 50b3c47 commit 581c87b
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions test/bio_addr_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ static BIO_ADDR *make_dummy_addr(int family)

static int bio_addr_is_eq(const BIO_ADDR *a, const BIO_ADDR *b)
{
struct sockaddr_storage adata, bdata;
unsigned char *adata = NULL, *bdata = NULL;
size_t alen, blen;
int ret = 0;

/* True even if a and b are NULL */
if (a == b)
Expand All @@ -98,23 +99,34 @@ static int bio_addr_is_eq(const BIO_ADDR *a, const BIO_ADDR *b)
if (BIO_ADDR_rawport(a) != BIO_ADDR_rawport(b))
return 0;

if (!BIO_ADDR_rawaddress(a, NULL, &alen)
|| alen > sizeof(adata)
|| !BIO_ADDR_rawaddress(a, &adata, &alen))
if (!BIO_ADDR_rawaddress(a, NULL, &alen))
return 0;

if (!BIO_ADDR_rawaddress(a, NULL, &blen)
|| blen > sizeof(bdata)
|| !BIO_ADDR_rawaddress(a, &bdata, &blen))
return 0;
if (!BIO_ADDR_rawaddress(b, NULL, &blen))
goto err;

if (alen != blen)
return 0;

if (alen == 0)
return 1;

return memcmp(&adata, &bdata, alen) == 0;
adata = OPENSSL_malloc(alen);
if (!TEST_ptr(adata)
|| !BIO_ADDR_rawaddress(a, adata, &alen))
goto err;

bdata = OPENSSL_malloc(blen);
if (!TEST_ptr(bdata)
|| !BIO_ADDR_rawaddress(b, bdata, &blen))
goto err;

ret = (memcmp(adata, bdata, alen) == 0);

err:
OPENSSL_free(adata);
OPENSSL_free(bdata);
return ret;
}

static int test_bio_addr_copy_dup(int idx)
Expand Down

0 comments on commit 581c87b

Please sign in to comment.