cpu_identify: check ID against number of processors.

Fix for PR/39955.
This commit is contained in:
rmind 2008-11-19 11:05:40 +00:00
parent 12f42819da
commit cdaedad50c

View File

@ -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 <sys/cdefs.h>
__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 <sys/param.h>
@ -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)