summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Obser <florian@cvs.openbsd.org>2014-04-23 09:10:54 +0000
committerFlorian Obser <florian@cvs.openbsd.org>2014-04-23 09:10:54 +0000
commit83a6e338928cd40c00c59cf54588be04da926729 (patch)
treeb71270cc22bc70cb39b42d433a1458c1233cd7b1
parent0707b727131a239f2173f8474daed8d4d38b7257 (diff)
Add error checking to sysctl. While there pass in an int otherwise
it failes with ENOMEM in traceroute. OK benno@
-rw-r--r--usr.sbin/traceroute/traceroute.c10
-rw-r--r--usr.sbin/traceroute6/traceroute6.c5
2 files changed, 9 insertions, 6 deletions
diff --git a/usr.sbin/traceroute/traceroute.c b/usr.sbin/traceroute/traceroute.c
index fd023ef45ed..441d8fe2a8d 100644
--- a/usr.sbin/traceroute/traceroute.c
+++ b/usr.sbin/traceroute/traceroute.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: traceroute.c,v 1.117 2014/04/23 08:58:26 florian Exp $ */
+/* $OpenBSD: traceroute.c,v 1.118 2014/04/23 09:10:53 florian Exp $ */
/* $NetBSD: traceroute.c,v 1.10 1995/05/21 15:50:45 mycroft Exp $ */
/*-
@@ -315,7 +315,7 @@ main(int argc, char *argv[])
int ch, i, lsrr = 0, on = 1, probe, seq = 0, tos = 0, error;
int last_tos = 0, tos_returned;
struct addrinfo hints, *res;
- size_t size = sizeof(max_ttl);
+ size_t size;
struct sockaddr_in from4, to4;
struct sockaddr *from, *to;
struct hostent *hp;
@@ -339,8 +339,10 @@ main(int argc, char *argv[])
if (setresuid(uid, uid, uid) == -1)
err(1, "setresuid");
- (void) sysctl(mib, sizeof(mib)/sizeof(mib[0]), &max_ttl, &size,
- NULL, 0);
+ size = sizeof(i);
+ if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &i, &size, NULL, 0) == -1)
+ err(1, "sysctl");
+ max_ttl = i;
while ((ch = getopt(argc, argv, "AcDdf:g:Ilm:nP:p:q:Ss:t:V:vw:x"))
!= -1)
diff --git a/usr.sbin/traceroute6/traceroute6.c b/usr.sbin/traceroute6/traceroute6.c
index 2046420fca4..8e17a429eb3 100644
--- a/usr.sbin/traceroute6/traceroute6.c
+++ b/usr.sbin/traceroute6/traceroute6.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: traceroute6.c,v 1.88 2014/04/23 09:09:28 florian Exp $ */
+/* $OpenBSD: traceroute6.c,v 1.89 2014/04/23 09:10:53 florian Exp $ */
/* $KAME: traceroute6.c,v 1.63 2002/10/24 12:53:25 itojun Exp $ */
/*
@@ -363,7 +363,8 @@ main(int argc, char *argv[])
err(1, "setresuid");
size = sizeof(i);
- (void) sysctl(mib, sizeof(mib)/sizeof(mib[0]), &i, &size, NULL, 0);
+ if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &i, &size, NULL, 0) == -1)
+ err(1, "sysctl");
max_hops = i;
/* specify to tell receiving interface */