diff options
author | Theo Buehler <tb@cvs.openbsd.org> | 2022-01-07 22:46:06 +0000 |
---|---|---|
committer | Theo Buehler <tb@cvs.openbsd.org> | 2022-01-07 22:46:06 +0000 |
commit | c633b1584510798e5ac778467da973a56bfe41f4 (patch) | |
tree | 3eadbd0c3a6dec6f3ddd0f69a75a348bc15417eb | |
parent | e5e1a863580f4b6c2dffc3814cf9a5d2bf549a8e (diff) |
Add some workarounds to make build_addr_block_test_data const.
-rw-r--r-- | regress/lib/libcrypto/x509/rfc3779/rfc3779.c | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/regress/lib/libcrypto/x509/rfc3779/rfc3779.c b/regress/lib/libcrypto/x509/rfc3779/rfc3779.c index 384d1441e46..d9b3007ac27 100644 --- a/regress/lib/libcrypto/x509/rfc3779/rfc3779.c +++ b/regress/lib/libcrypto/x509/rfc3779/rfc3779.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rfc3779.c,v 1.5 2022/01/06 14:55:52 tb Exp $ */ +/* $OpenBSD: rfc3779.c,v 1.6 2022/01/07 22:46:05 tb Exp $ */ /* * Copyright (c) 2021 Theo Buehler <tb@openbsd.org> * @@ -471,12 +471,7 @@ struct build_addr_block_test_data { int afi_len; }; -/* - * This struct isn't const since the address arguments of - * X509v3_addr_add_{prefix,range}() aren't const and it's - * not worth working around this. - */ -struct build_addr_block_test_data build_addr_block_tests[] = { +const struct build_addr_block_test_data build_addr_block_tests[] = { { .description = "RFC 3779, Appendix B, example 1", .addrs = { @@ -791,15 +786,22 @@ addr_block_get_safi(const struct ip_addr_block *addr) static int addr_block_add_ipv4_addr(IPAddrBlocks *block, enum choice_type type, - union ipv4_choice *ipv4, unsigned int *safi) + const union ipv4_choice *ipv4, unsigned int *safi) { + unsigned char addr[RAW_ADDRESS_SIZE] = {0}; + unsigned char min[RAW_ADDRESS_SIZE]; + unsigned char max[RAW_ADDRESS_SIZE]; + switch (type) { case choice_prefix: + memcpy(addr, ipv4->prefix.addr, ipv4->prefix.addr_len); return X509v3_addr_add_prefix(block, IANA_AFI_IPV4, safi, - ipv4->prefix.addr, ipv4->prefix.prefix_len); + addr, ipv4->prefix.prefix_len); case choice_range: + memcpy(min, ipv4->range.min, sizeof(ipv4->range.min)); + memcpy(max, ipv4->range.max, sizeof(ipv4->range.max)); return X509v3_addr_add_range(block, IANA_AFI_IPV4, safi, - ipv4->range.min, ipv4->range.max); + min, max); case choice_inherit: return X509v3_addr_add_inherit(block, IANA_AFI_IPV4, safi); case choice_last: @@ -810,15 +812,22 @@ addr_block_add_ipv4_addr(IPAddrBlocks *block, enum choice_type type, static int addr_block_add_ipv6_addr(IPAddrBlocks *block, enum choice_type type, - union ipv6_choice *ipv6, unsigned int *safi) + const union ipv6_choice *ipv6, unsigned int *safi) { + unsigned char addr[RAW_ADDRESS_SIZE] = {0}; + unsigned char min[RAW_ADDRESS_SIZE]; + unsigned char max[RAW_ADDRESS_SIZE]; + switch (type) { case choice_prefix: + memcpy(addr, ipv6->prefix.addr, ipv6->prefix.addr_len); return X509v3_addr_add_prefix(block, IANA_AFI_IPV6, safi, - ipv6->prefix.addr, ipv6->prefix.prefix_len); + addr, ipv6->prefix.prefix_len); case choice_range: + memcpy(min, ipv6->range.min, sizeof(ipv6->range.min)); + memcpy(max, ipv6->range.max, sizeof(ipv6->range.max)); return X509v3_addr_add_range(block, IANA_AFI_IPV6, safi, - ipv6->range.min, ipv6->range.max); + min, max); case choice_inherit: return X509v3_addr_add_inherit(block, IANA_AFI_IPV6, safi); case choice_last: @@ -828,10 +837,10 @@ addr_block_add_ipv6_addr(IPAddrBlocks *block, enum choice_type type, } static int -addr_block_add_addrs(IPAddrBlocks *block, struct ip_addr_block addrs[]) +addr_block_add_addrs(IPAddrBlocks *block, const struct ip_addr_block addrs[]) { - struct ip_addr_block *addr; - unsigned int *safi; + const struct ip_addr_block *addr; + unsigned int *safi; for (addr = &addrs[0]; addr->type != choice_last; addr++) { safi = addr_block_get_safi(addr); @@ -856,7 +865,7 @@ addr_block_add_addrs(IPAddrBlocks *block, struct ip_addr_block addrs[]) } static int -build_addr_block_test(struct build_addr_block_test_data *test) +build_addr_block_test(const struct build_addr_block_test_data *test) { IPAddrBlocks *addrs = NULL; unsigned char *out = NULL; |