From cdaedad50c36a85bde505b84fbc212a0ba2dc2d0 Mon Sep 17 00:00:00 2001 From: rmind Date: Wed, 19 Nov 2008 11:05:40 +0000 Subject: [PATCH] cpu_identify: check ID against number of processors. Fix for PR/39955. --- usr.sbin/cpuctl/cpuctl.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/usr.sbin/cpuctl/cpuctl.c b/usr.sbin/cpuctl/cpuctl.c index 847281fa99fc..e88d32b69b2e 100644 --- a/usr.sbin/cpuctl/cpuctl.c +++ b/usr.sbin/cpuctl/cpuctl.c @@ -1,4 +1,4 @@ -/* $NetBSD: cpuctl.c,v 1.10 2008/10/15 08:22:06 ad Exp $ */ +/* $NetBSD: cpuctl.c,v 1.11 2008/11/19 11:05:40 rmind Exp $ */ /*- * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #ifndef lint #include -__RCSID("$NetBSD: cpuctl.c,v 1.10 2008/10/15 08:22:06 ad Exp $"); +__RCSID("$NetBSD: cpuctl.c,v 1.11 2008/11/19 11:05:40 rmind Exp $"); #endif /* not lint */ #include @@ -147,13 +147,17 @@ void cpu_identify(char **argv) { char name[32]; - int id, np; + unsigned int id, np; cpuset_t *cpuset; + np = sysconf(_SC_NPROCESSORS_CONF); id = getcpuid(argv); + + if (id >= np) + errx(EXIT_FAILURE, "invalid CPU number"); + snprintf(name, sizeof(name), "cpu%d", id); - np = sysconf(_SC_NPROCESSORS_CONF); if (np != 0) { cpuset = cpuset_create(); if (cpuset == NULL)