From e25ccd667e01e3a9e37f06e7cc79fb7ac0f6e3f4 Mon Sep 17 00:00:00 2001 From: tb <> Date: Sun, 4 Jan 2026 09:43:52 +0000 Subject: asn1basic: add missing test from BoringSSL's test suite This is another test that fails due to the bug in i2c_ASN1_BIT_STRING(). --- src/regress/lib/libcrypto/asn1/asn1basic.c | 33 +++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/regress/lib/libcrypto/asn1/asn1basic.c b/src/regress/lib/libcrypto/asn1/asn1basic.c index e6df6559f5..0666e5b061 100644 --- a/src/regress/lib/libcrypto/asn1/asn1basic.c +++ b/src/regress/lib/libcrypto/asn1/asn1basic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: asn1basic.c,v 1.19 2026/01/04 09:42:32 tb Exp $ */ +/* $OpenBSD: asn1basic.c,v 1.20 2026/01/04 09:43:52 tb Exp $ */ /* * Copyright (c) 2017, 2021 Joel Sing * Copyright (c) 2021 Google, Inc @@ -237,6 +237,8 @@ static const uint8_t asn1_bit_string_10010[] = { 0x03, 0x02, 0x03, 0x90, }; +static const uint8_t asn1_bit_string_zeroes[64] = { 0 }; + static int asn1_bit_string_set_bit_test(void) { @@ -625,6 +627,35 @@ asn1_bit_string_set_bit_test(void) asn1_bit_string_1001, sizeof(asn1_bit_string_1001))) goto failed; + /* + * ASN1_BIT_STRING_set() also truncates + */ + + ASN1_BIT_STRING_free(abs); + abs = NULL; + + if ((abs = ASN1_BIT_STRING_new()) == NULL) { + fprintf(stderr, "FAIL: ASN1_BIT_STRING_new\n"); + goto failed; + } + + if (!ASN1_STRING_set(abs, asn1_bit_string_zeroes, + sizeof(asn1_bit_string_zeroes))) { + fprintf(stderr, "FAIL: ASN1_BIT_STRING_set zeroes\n"); + goto failed; + } + + freezero(der, der_len); + der = NULL; + if ((der_len = i2d_ASN1_BIT_STRING(abs, &der)) <= 0) { + fprintf(stderr, "FAIL: i2d_ASN1_BIT_STRING\n"); + der_len = 0; + goto failed; + } + if (!asn1_compare_bytes("BIT STRING all zeroes", der, der_len, + asn1_bit_string_empty, sizeof(asn1_bit_string_empty))) + goto failed; + failed = 0; failed: -- cgit v1.2.3-55-g6feb