diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2009-12-14 17:38:19 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2009-12-14 17:38:19 +0000 |
commit | e6042e09cd6a4ab6af45b46a78f83abad92192e3 (patch) | |
tree | e5e69b60218b1acb66e49841a70807e94d2d0504 | |
parent | f810c45815c50ca4a68e2dd51ea174ffb7c1a312 (diff) |
addr2sa() will return NULL for AID_UNSPEC and pfkey_send() may end up with
one of the src/dst addrs as AID_UNSPEC. So we need to check for NULL before
copying. Fixes a crash seen with tcp-md5 enabled peers.
-rw-r--r-- | usr.sbin/bgpd/pfkey.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/usr.sbin/bgpd/pfkey.c b/usr.sbin/bgpd/pfkey.c index 6832fa971ff..653565ad3b8 100644 --- a/usr.sbin/bgpd/pfkey.c +++ b/usr.sbin/bgpd/pfkey.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfkey.c,v 1.39 2009/12/06 11:42:22 claudio Exp $ */ +/* $OpenBSD: pfkey.c,v 1.40 2009/12/14 17:38:18 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -74,6 +74,7 @@ pfkey_send(int sd, uint8_t satype, uint8_t mtype, uint8_t dir, int len = 0; int iov_cnt; struct sockaddr_storage ssrc, sdst, speer, smask, dmask; + struct sockaddr *saptr; if (!pid) pid = getpid(); @@ -81,7 +82,8 @@ pfkey_send(int sd, uint8_t satype, uint8_t mtype, uint8_t dir, /* we need clean sockaddr... no ports set */ bzero(&ssrc, sizeof(ssrc)); bzero(&smask, sizeof(smask)); - memcpy(&ssrc, addr2sa(src, 0), sizeof(ssrc)); + if ((saptr = addr2sa(src, 0))) + memcpy(&ssrc, saptr, sizeof(ssrc)); switch (src->aid) { case AID_INET: memset(&((struct sockaddr_in *)&smask)->sin_addr, 0xff, 32/8); @@ -101,7 +103,8 @@ pfkey_send(int sd, uint8_t satype, uint8_t mtype, uint8_t dir, bzero(&sdst, sizeof(sdst)); bzero(&dmask, sizeof(dmask)); - memcpy(&sdst, addr2sa(dst, 0), sizeof(sdst)); + if ((saptr = addr2sa(dst, 0))) + memcpy(&sdst, saptr, sizeof(sdst)); switch (dst->aid) { case AID_INET: memset(&((struct sockaddr_in *)&dmask)->sin_addr, 0xff, 32/8); |