summaryrefslogtreecommitdiffstats
path: root/sbin/route/show.c
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2013-03-21 04:43:15 +0000
committerderaadt <deraadt@openbsd.org>2013-03-21 04:43:15 +0000
commit8ae2d34229e0135c1ca81f3a93bd8889498ab288 (patch)
tree958397ace1a8632387c398ff35079e6990aaf1c3 /sbin/route/show.c
parentremove excessive includes (diff)
downloadwireguard-openbsd-8ae2d34229e0135c1ca81f3a93bd8889498ab288.tar.xz
wireguard-openbsd-8ae2d34229e0135c1ca81f3a93bd8889498ab288.zip
create realloc() loops around sysctl for array-based mibs, in programs
which want a "full" dump ok dlg
Diffstat (limited to 'sbin/route/show.c')
-rw-r--r--sbin/route/show.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/sbin/route/show.c b/sbin/route/show.c
index 961e9ababe9..8a485d1d9f8 100644
--- a/sbin/route/show.c
+++ b/sbin/route/show.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: show.c,v 1.92 2012/12/04 02:30:33 deraadt Exp $ */
+/* $OpenBSD: show.c,v 1.93 2013/03/21 04:43:17 deraadt Exp $ */
/* $NetBSD: show.c,v 1.1 1996/11/15 18:01:41 gwr Exp $ */
/*
@@ -142,14 +142,20 @@ p_rttables(int af, u_int tableid, int hastable)
} else
mcnt = 6;
- if (sysctl(mib, mcnt, NULL, &needed, NULL, 0) < 0)
- err(1, "route-sysctl-estimate");
- if (needed > 0) {
- if ((buf = malloc(needed)) == 0)
- err(1, NULL);
- if (sysctl(mib, mcnt, buf, &needed, NULL, 0) < 0)
+ while (1) {
+ if (sysctl(mib, mcnt, NULL, &needed, NULL, 0) == -1)
+ err(1, "route-sysctl-estimate");
+ if (needed == 0)
+ break;
+ if ((buf = realloc(buf, needed)) == NULL)
+ err(1, "realloc");
+ if (sysctl(mib, mcnt, buf, &needed, NULL, 0) == -1) {
+ if (errno == ENOMEM)
+ continue;
err(1, "sysctl of routing table");
+ }
lim = buf + needed;
+ break;
}
printf("Routing tables\n");