From: florian Date: Wed, 23 Apr 2014 09:10:53 +0000 (+0000) Subject: Add error checking to sysctl. While there pass in an int otherwise X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=541bcf03da6b733945afa27db5def5e3a3513b00;p=openbsd Add error checking to sysctl. While there pass in an int otherwise it failes with ENOMEM in traceroute. OK benno@ --- 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 */