From 4671eb33dcbfe65ece8c718b62e2b0edeb058316 Mon Sep 17 00:00:00 2001 From: jsing <> Date: Fri, 13 Mar 2020 15:55:00 +0000 Subject: Add regress for CBB_add_space(). --- src/regress/lib/libssl/bytestring/bytestringtest.c | 42 +++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/regress/lib/libssl/bytestring/bytestringtest.c b/src/regress/lib/libssl/bytestring/bytestringtest.c index 0e9f5f47e5..1304db2c3e 100644 --- a/src/regress/lib/libssl/bytestring/bytestringtest.c +++ b/src/regress/lib/libssl/bytestring/bytestringtest.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bytestringtest.c,v 1.12 2018/08/16 18:40:19 jsing Exp $ */ +/* $OpenBSD: bytestringtest.c,v 1.13 2020/03/13 15:55:00 jsing Exp $ */ /* * Copyright (c) 2014, Google Inc. * @@ -297,6 +297,45 @@ err: return ret; } +static int +test_cbb_add_space(void) +{ + static const uint8_t kExpected[] = {1, 2, 0, 0, 0, 0, 7, 8}; + uint8_t *buf = NULL; + size_t buf_len; + uint8_t *data; + int ret = 0; + CBB cbb; + + CHECK(CBB_init(&cbb, 100)); + + CHECK_GOTO(CBB_add_u16(&cbb, 0x102)); + CHECK_GOTO(CBB_add_space(&cbb, &data, 4)); + CHECK_GOTO(CBB_add_u16(&cbb, 0x708)); + CHECK_GOTO(CBB_finish(&cbb, &buf, &buf_len)); + + ret |= (buf_len == sizeof(kExpected) + && memcmp(buf, kExpected, buf_len) == 0); + + memset(buf, 0xa5, buf_len); + CHECK(CBB_init_fixed(&cbb, buf, buf_len)); + + CHECK_GOTO(CBB_add_u16(&cbb, 0x102)); + CHECK_GOTO(CBB_add_space(&cbb, &data, 4)); + CHECK_GOTO(CBB_add_u16(&cbb, 0x708)); + CHECK_GOTO(CBB_finish(&cbb, NULL, NULL)); + + ret |= (buf_len == sizeof(kExpected) + && memcmp(buf, kExpected, buf_len) == 0); + + if (0) { +err: + CBB_cleanup(&cbb); + } + free(buf); + return ret; +} + static int test_cbb_fixed(void) { @@ -857,6 +896,7 @@ main(void) failed |= !test_get_prefixed_bad(); failed |= !test_get_asn1(); failed |= !test_cbb_basic(); + failed |= !test_cbb_add_space(); failed |= !test_cbb_fixed(); failed |= !test_cbb_finish_child(); failed |= !test_cbb_discard_child(); -- cgit v1.2.3-55-g6feb