summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2020-03-13 15:55:00 +0000
committerjsing <>2020-03-13 15:55:00 +0000
commit4671eb33dcbfe65ece8c718b62e2b0edeb058316 (patch)
tree770122c211c087d8db5e4d136e92ade087524dfc
parentc809ac6677ff2c1852850a8ba62bf7c05d60d040 (diff)
downloadopenbsd-4671eb33dcbfe65ece8c718b62e2b0edeb058316.tar.gz
openbsd-4671eb33dcbfe65ece8c718b62e2b0edeb058316.tar.bz2
openbsd-4671eb33dcbfe65ece8c718b62e2b0edeb058316.zip
Add regress for CBB_add_space().
-rw-r--r--src/regress/lib/libssl/bytestring/bytestringtest.c42
1 files changed, 41 insertions, 1 deletions
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 @@
1/* $OpenBSD: bytestringtest.c,v 1.12 2018/08/16 18:40:19 jsing Exp $ */ 1/* $OpenBSD: bytestringtest.c,v 1.13 2020/03/13 15:55:00 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014, Google Inc. 3 * Copyright (c) 2014, Google Inc.
4 * 4 *
@@ -298,6 +298,45 @@ err:
298} 298}
299 299
300static int 300static int
301test_cbb_add_space(void)
302{
303 static const uint8_t kExpected[] = {1, 2, 0, 0, 0, 0, 7, 8};
304 uint8_t *buf = NULL;
305 size_t buf_len;
306 uint8_t *data;
307 int ret = 0;
308 CBB cbb;
309
310 CHECK(CBB_init(&cbb, 100));
311
312 CHECK_GOTO(CBB_add_u16(&cbb, 0x102));
313 CHECK_GOTO(CBB_add_space(&cbb, &data, 4));
314 CHECK_GOTO(CBB_add_u16(&cbb, 0x708));
315 CHECK_GOTO(CBB_finish(&cbb, &buf, &buf_len));
316
317 ret |= (buf_len == sizeof(kExpected)
318 && memcmp(buf, kExpected, buf_len) == 0);
319
320 memset(buf, 0xa5, buf_len);
321 CHECK(CBB_init_fixed(&cbb, buf, buf_len));
322
323 CHECK_GOTO(CBB_add_u16(&cbb, 0x102));
324 CHECK_GOTO(CBB_add_space(&cbb, &data, 4));
325 CHECK_GOTO(CBB_add_u16(&cbb, 0x708));
326 CHECK_GOTO(CBB_finish(&cbb, NULL, NULL));
327
328 ret |= (buf_len == sizeof(kExpected)
329 && memcmp(buf, kExpected, buf_len) == 0);
330
331 if (0) {
332err:
333 CBB_cleanup(&cbb);
334 }
335 free(buf);
336 return ret;
337}
338
339static int
301test_cbb_fixed(void) 340test_cbb_fixed(void)
302{ 341{
303 CBB cbb; 342 CBB cbb;
@@ -857,6 +896,7 @@ main(void)
857 failed |= !test_get_prefixed_bad(); 896 failed |= !test_get_prefixed_bad();
858 failed |= !test_get_asn1(); 897 failed |= !test_get_asn1();
859 failed |= !test_cbb_basic(); 898 failed |= !test_cbb_basic();
899 failed |= !test_cbb_add_space();
860 failed |= !test_cbb_fixed(); 900 failed |= !test_cbb_fixed();
861 failed |= !test_cbb_finish_child(); 901 failed |= !test_cbb_finish_child();
862 failed |= !test_cbb_discard_child(); 902 failed |= !test_cbb_discard_child();