diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2017-01-23 23:30:44 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2017-01-23 23:30:44 +0000 |
commit | 363841924171c532cc152b7d2ed30df8f17d511a (patch) | |
tree | a995d436bf56b210e310537ac323decd8cac070b /usr.sbin/bgpd/util.c | |
parent | 49b8c6d0962e31b32f666a6eed97dd83169ea71b (diff) |
Make util.c fatal() free by allowing undefined behaviour in prefix_compare.
If you pass in crap then you will not get gold back.
Diffstat (limited to 'usr.sbin/bgpd/util.c')
-rw-r--r-- | usr.sbin/bgpd/util.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/usr.sbin/bgpd/util.c b/usr.sbin/bgpd/util.c index a660f38a393..b6d908a1560 100644 --- a/usr.sbin/bgpd/util.c +++ b/usr.sbin/bgpd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.22 2017/01/13 18:59:12 phessler Exp $ */ +/* $OpenBSD: util.c,v 1.23 2017/01/23 23:30:43 claudio Exp $ */ /* * Copyright (c) 2006 Claudio Jeker <claudio@openbsd.org> @@ -405,6 +405,10 @@ aspath_extract(const void *seg, int pos) return (ntohl(as)); } +/* + * This function will have undefined behaviour if the passed in prefixlen is + * to large for the respective bgpd_addr address family. + */ int prefix_compare(const struct bgpd_addr *a, const struct bgpd_addr *b, int prefixlen) @@ -421,7 +425,7 @@ prefix_compare(const struct bgpd_addr *a, const struct bgpd_addr *b, if (prefixlen == 0) return (0); if (prefixlen > 32) - fatalx("prefix_cmp: bad IPv4 prefixlen"); + return (-1); mask = htonl(prefixlen2mask(prefixlen)); aa = ntohl(a->v4.s_addr & mask); ba = ntohl(b->v4.s_addr & mask); @@ -432,7 +436,7 @@ prefix_compare(const struct bgpd_addr *a, const struct bgpd_addr *b, if (prefixlen == 0) return (0); if (prefixlen > 128) - fatalx("prefix_cmp: bad IPv6 prefixlen"); + return (-1); for (i = 0; i < prefixlen / 8; i++) if (a->v6.s6_addr[i] != b->v6.s6_addr[i]) return (a->v6.s6_addr[i] - b->v6.s6_addr[i]); @@ -447,7 +451,7 @@ prefix_compare(const struct bgpd_addr *a, const struct bgpd_addr *b, return (0); case AID_VPN_IPv4: if (prefixlen > 32) - fatalx("prefix_cmp: bad IPv4 VPN prefixlen"); + return (-1); if (betoh64(a->vpn4.rd) > betoh64(b->vpn4.rd)) return (1); if (betoh64(a->vpn4.rd) < betoh64(b->vpn4.rd)) @@ -463,8 +467,6 @@ prefix_compare(const struct bgpd_addr *a, const struct bgpd_addr *b, return (-1); return (memcmp(a->vpn4.labelstack, b->vpn4.labelstack, a->vpn4.labellen)); - default: - fatalx("prefix_cmp: unknown af"); } return (-1); } |