summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Benoit <benno@cvs.openbsd.org>2020-12-30 18:57:29 +0000
committerSebastian Benoit <benno@cvs.openbsd.org>2020-12-30 18:57:29 +0000
commit861c66e334fb96b017f25eb6d5d1fb3fb2ff7cd8 (patch)
treeea4d303ae6173486470402043631aae7fd2b9145
parent20400879b5bbfe95497866f44998e6dbe0324688 (diff)
getifaddrs() can return entries where ifa_addr is NULL. Check for this
before accessing anything in ifa_addr. ok claudio@
-rw-r--r--lib/libc/rpc/get_myaddress.c3
-rw-r--r--lib/libc/rpc/pmap_rmt.c8
-rw-r--r--regress/sys/netinet/in_pcbbind/runtest.c5
-rw-r--r--sbin/ifconfig/ifconfig.c15
4 files changed, 19 insertions, 12 deletions
diff --git a/lib/libc/rpc/get_myaddress.c b/lib/libc/rpc/get_myaddress.c
index d0ac78f796e..99c0dabee70 100644
--- a/lib/libc/rpc/get_myaddress.c
+++ b/lib/libc/rpc/get_myaddress.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: get_myaddress.c,v 1.15 2015/09/13 15:36:56 guenther Exp $ */
+/* $OpenBSD: get_myaddress.c,v 1.16 2020/12/30 18:56:35 benno Exp $ */
/*
* Copyright (c) 2010, Oracle America, Inc.
@@ -67,6 +67,7 @@ get_myaddress(struct sockaddr_in *addr)
again:
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
if ((ifa->ifa_flags & IFF_UP) &&
+ ifa->ifa_addr != NULL &&
ifa->ifa_addr->sa_family == AF_INET &&
(loopback == 1 && (ifa->ifa_flags & IFF_LOOPBACK))) {
*addr = *((struct sockaddr_in *)ifa->ifa_addr);
diff --git a/lib/libc/rpc/pmap_rmt.c b/lib/libc/rpc/pmap_rmt.c
index 097999b5ae6..7d971f690a1 100644
--- a/lib/libc/rpc/pmap_rmt.c
+++ b/lib/libc/rpc/pmap_rmt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pmap_rmt.c,v 1.35 2019/06/28 13:32:42 deraadt Exp $ */
+/* $OpenBSD: pmap_rmt.c,v 1.36 2020/12/30 18:56:35 benno Exp $ */
/*
* Copyright (c) 2010, Oracle America, Inc.
@@ -163,7 +163,8 @@ newgetbroadcastnets(struct in_addr **addrsp)
return 0;
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
- if (ifa->ifa_addr->sa_family != AF_INET)
+ if (ifa->ifa_addr == NULL ||
+ ifa->ifa_addr->sa_family != AF_INET)
continue;
if ((ifa->ifa_flags & IFF_BROADCAST) &&
(ifa->ifa_flags & IFF_UP) &&
@@ -180,7 +181,8 @@ newgetbroadcastnets(struct in_addr **addrsp)
}
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
- if (ifa->ifa_addr->sa_family != AF_INET)
+ if (ifa->ifa_addr == NULL ||
+ ifa->ifa_addr->sa_family != AF_INET)
continue;
if ((ifa->ifa_flags & IFF_BROADCAST) &&
(ifa->ifa_flags & IFF_UP) &&
diff --git a/regress/sys/netinet/in_pcbbind/runtest.c b/regress/sys/netinet/in_pcbbind/runtest.c
index e26d2832dce..2842a2c7b7d 100644
--- a/regress/sys/netinet/in_pcbbind/runtest.c
+++ b/regress/sys/netinet/in_pcbbind/runtest.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: runtest.c,v 1.5 2017/07/06 13:20:54 bluhm Exp $ */
+/* $OpenBSD: runtest.c,v 1.6 2020/12/30 18:56:56 benno Exp $ */
/*
* Copyright (c) 2015 Vincent Gross <vincent.gross@kilob.yt>
*
@@ -415,7 +415,8 @@ main(int argc, char *argv[])
err(2, "getifaddrs()");
curifa = ifap;
while (curifa) {
- if (memcmp(curifa->ifa_addr,
+ if (curifa->ifa_addr != NULL &&
+ memcmp(curifa->ifa_addr,
mifa->ai_addr,
mifa->ai_addrlen) == 0)
break;
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
index 3799cc3a8e9..3d8f6b3b9c2 100644
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ifconfig.c,v 1.430 2020/11/06 21:24:47 kn Exp $ */
+/* $OpenBSD: ifconfig.c,v 1.431 2020/12/30 18:57:28 benno Exp $ */
/* $NetBSD: ifconfig.c,v 1.40 1997/10/01 02:19:43 enami Exp $ */
/*
@@ -1180,12 +1180,13 @@ printif(char *name, int ifaliases)
}
}
/* quickhack: sizeof(ifr) < sizeof(ifr6) */
- if (ifa->ifa_addr->sa_family == AF_INET6) {
+ if (ifa->ifa_addr != NULL &&
+ ifa->ifa_addr->sa_family == AF_INET6) {
memset(&ifr6, 0, sizeof(ifr6));
memcpy(&ifr6.ifr_addr, ifa->ifa_addr,
MINIMUM(sizeof(ifr6.ifr_addr), ifa->ifa_addr->sa_len));
ifrp = (struct ifreq *)&ifr6;
- } else {
+ } else if (ifa->ifa_addr != NULL) {
memset(&ifr, 0, sizeof(ifr));
memcpy(&ifr.ifr_addr, ifa->ifa_addr,
MINIMUM(sizeof(ifr.ifr_addr), ifa->ifa_addr->sa_len));
@@ -1194,7 +1195,8 @@ printif(char *name, int ifaliases)
strlcpy(ifname, ifa->ifa_name, sizeof(ifname));
strlcpy(ifrp->ifr_name, ifa->ifa_name, sizeof(ifrp->ifr_name));
- if (ifa->ifa_addr->sa_family == AF_LINK) {
+ if (ifa->ifa_addr != NULL &&
+ ifa->ifa_addr->sa_family == AF_LINK) {
namep = ifa->ifa_name;
if (getinfo(ifrp, 0) < 0)
continue;
@@ -1209,8 +1211,9 @@ printif(char *name, int ifaliases)
if (!namep || !strcmp(namep, ifa->ifa_name)) {
const struct afswtch *p;
- if (ifa->ifa_addr->sa_family == AF_INET &&
- ifaliases == 0 && noinet == 0)
+ if (ifa->ifa_addr == NULL ||
+ (ifa->ifa_addr->sa_family == AF_INET &&
+ ifaliases == 0 && noinet == 0))
continue;
if ((p = afp) != NULL) {
if (ifa->ifa_addr->sa_family == p->af_af)