summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorAngelos D. Keromytis <angelos@cvs.openbsd.org>2001-05-12 06:47:18 +0000
committerAngelos D. Keromytis <angelos@cvs.openbsd.org>2001-05-12 06:47:18 +0000
commita5ef99bc88ad4772c2bdfc2ff122bb719a4eae1d (patch)
tree319768cbe136ea15741d1af8e10c6f9d5a5e1eaf /sbin
parent09c72b2bcbed95a18c3502c35052bc3e1d2f9ebb (diff)
Better argument checking for kmemstats.
Diffstat (limited to 'sbin')
-rw-r--r--sbin/sysctl/sysctl.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c
index 827d269b514..dad35ddbcfd 100644
--- a/sbin/sysctl/sysctl.c
+++ b/sbin/sysctl/sysctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sysctl.c,v 1.61 2001/05/11 06:43:41 angelos Exp $ */
+/* $OpenBSD: sysctl.c,v 1.62 2001/05/12 06:47:17 angelos Exp $ */
/* $NetBSD: sysctl.c,v 1.9 1995/09/30 07:12:50 thorpej Exp $ */
/*
@@ -44,7 +44,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)sysctl.c 8.5 (Berkeley) 5/9/95";
#else
-static char *rcsid = "$OpenBSD: sysctl.c,v 1.61 2001/05/11 06:43:41 angelos Exp $";
+static char *rcsid = "$OpenBSD: sysctl.c,v 1.62 2001/05/12 06:47:17 angelos Exp $";
#endif
#endif /* not lint */
@@ -1492,12 +1492,21 @@ sysctl_malloc(string, bufpp, mib, flags, typep)
return(-1);
}
ptr = strstr(buf, name);
- if (ptr == NULL) /* Should never happen */
- return(-1);
- /* Catch weird prefix match -- XXX recovery ? */
+ tryagain:
+ if (ptr == NULL) {
+ warnx("fourth level name %s in %s is invalid", name,
+ string);
+ return(-1);
+ }
if ((*(ptr + strlen(name)) != ',') &&
- (*(ptr + strlen(name)) != '\0'))
- return(-1);
+ (*(ptr + strlen(name)) != '\0')) {
+ ptr = strstr(ptr + 1, name); /* retry */
+ goto tryagain;
+ }
+ if ((ptr != buf) && (*(ptr - 1) != ',')) {
+ ptr = strstr(ptr + 1, name); /* retry */
+ goto tryagain;
+ }
for (i = 0, stor = 0; buf + i < ptr; i++)
if (buf[i] == ',')
stor++;