-/* $OpenBSD: cert.c,v 1.120 2023/12/10 14:18:23 job Exp $ */
+/* $OpenBSD: cert.c,v 1.121 2023/12/14 07:52:53 tb Exp $ */
/*
* Copyright (c) 2022 Theo Buehler <tb@openbsd.org>
* Copyright (c) 2021 Job Snijders <job@openbsd.org>
enum afi afi;
struct cert_ip *ips = NULL;
size_t ipsz = 0, sz;
- int i, j;
+ int ipv4_seen = 0, ipv6_seen = 0;
+ int i, j, ipaddrblocksz;
assert(*out_ips == NULL && *out_ipsz == 0);
- for (i = 0; i < sk_IPAddressFamily_num(addrblk); i++) {
+ ipaddrblocksz = sk_IPAddressFamily_num(addrblk);
+ if (ipaddrblocksz != 1 && ipaddrblocksz != 2) {
+ warnx("%s: RFC 6487 section 4.8.10: unexpected number of "
+ "ipAddrBlocks (got %d, expected 1 or 2)",
+ fn, ipaddrblocksz);
+ goto out;
+ }
+
+ for (i = 0; i < ipaddrblocksz; i++) {
af = sk_IPAddressFamily_value(addrblk, i);
switch (af->ipAddressChoice->type) {
goto out;
}
+ switch(afi) {
+ case AFI_IPV4:
+ if (ipv4_seen++ > 0) {
+ warnx("%s: RFC 6487 section 4.8.10: "
+ "IPv4 appears twice", fn);
+ goto out;
+ }
+ break;
+ case AFI_IPV6:
+ if (ipv6_seen++ > 0) {
+ warnx("%s: RFC 6487 section 4.8.10: "
+ "IPv6 appears twice", fn);
+ goto out;
+ }
+ break;
+ }
+
if (aors == NULL) {
if (!sbgp_addr_inherit(fn, ips, &ipsz, afi))
goto out;
-/* $OpenBSD: roa.c,v 1.71 2023/10/13 12:06:49 job Exp $ */
+/* $OpenBSD: roa.c,v 1.72 2023/12/14 07:52:53 tb Exp $ */
/*
* Copyright (c) 2022 Theo Buehler <tb@openbsd.org>
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
RouteOriginAttestation *roa;
const ROAIPAddressFamily *addrfam;
const STACK_OF(ROAIPAddress) *addrs;
- int addrsz;
+ int addrsz, ipv4_seen = 0, ipv6_seen = 0;
enum afi afi;
const ROAIPAddress *addr;
uint64_t maxlen;
}
ipaddrblocksz = sk_ROAIPAddressFamily_num(roa->ipAddrBlocks);
- if (ipaddrblocksz > 2) {
- warnx("%s: draft-rfc6482bis: too many ipAddrBlocks "
+ if (ipaddrblocksz != 1 && ipaddrblocksz != 2) {
+ warnx("%s: draft-rfc6482bis: unexpected number of ipAddrBlocks "
"(got %d, expected 1 or 2)", p->fn, ipaddrblocksz);
goto out;
}
goto out;
}
+ switch(afi) {
+ case AFI_IPV4:
+ if (ipv4_seen++ > 0) {
+ warnx("%s: RFC 6482bis section 4.3.2: "
+ "IPv4 appears twice", p->fn);
+ goto out;
+ }
+ break;
+ case AFI_IPV6:
+ if (ipv6_seen++ > 0) {
+ warnx("%s: RFC 6482bis section 4.3.2: "
+ "IPv6 appears twice", p->fn);
+ goto out;
+ }
+ break;
+ }
+
+ if (addrsz == 0) {
+ warnx("%s: RFC 6482bis, section 4.3.2: "
+ "empty ROAIPAddressFamily", p->fn);
+ goto out;
+ }
+
if (p->res->ipsz + addrsz >= MAX_IP_SIZE) {
warnx("%s: too many ROAIPAddress entries: limit %d",
p->fn, MAX_IP_SIZE);