Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/wscons wsmux_getmux: do not increment nwsmux if allo...
details: https://anonhg.NetBSD.org/src/rev/f26173e4e252
branches: trunk
changeset: 773258:f26173e4e252
user: rmind <rmind%NetBSD.org@localhost>
date: Mon Jan 30 01:54:08 2012 +0000
description:
wsmux_getmux: do not increment nwsmux if allocation fails (might cause buffer
overflow). Simplify slightly.
diffstat:
sys/dev/wscons/wsmux.c | 25 +++++++++----------------
1 files changed, 9 insertions(+), 16 deletions(-)
diffs (62 lines):
diff -r df7e19df6e0d -r f26173e4e252 sys/dev/wscons/wsmux.c
--- a/sys/dev/wscons/wsmux.c Mon Jan 30 00:56:19 2012 +0000
+++ b/sys/dev/wscons/wsmux.c Mon Jan 30 01:54:08 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: wsmux.c,v 1.53 2009/02/13 22:41:04 apb Exp $ */
+/* $NetBSD: wsmux.c,v 1.54 2012/01/30 01:54:08 rmind Exp $ */
/*
* Copyright (c) 1998, 2005 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wsmux.c,v 1.53 2009/02/13 22:41:04 apb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wsmux.c,v 1.54 2012/01/30 01:54:08 rmind Exp $");
#include "opt_compat_netbsd.h"
#include "opt_modular.h"
@@ -141,36 +141,29 @@
}
/* Keep track of all muxes that have been allocated */
+static struct wsmux_softc **wsmuxdevs = NULL;
static int nwsmux = 0;
-static struct wsmux_softc **wsmuxdevs;
/* Return mux n, create if necessary */
struct wsmux_softc *
wsmux_getmux(int n)
{
struct wsmux_softc *sc;
- int i;
- void *new;
n = WSMUXDEV(n); /* limit range */
/* Make sure there is room for mux n in the table */
if (n >= nwsmux) {
- i = nwsmux;
- nwsmux = n + 1;
- if (i != 0)
- new = realloc(wsmuxdevs, nwsmux * sizeof (*wsmuxdevs),
- M_DEVBUF, M_NOWAIT);
- else
- new = malloc(nwsmux * sizeof (*wsmuxdevs),
- M_DEVBUF, M_NOWAIT);
+ void *new;
+
+ new = realloc(wsmuxdevs, (n + 1) * sizeof(*wsmuxdevs),
+ M_DEVBUF, M_ZERO | M_NOWAIT);
if (new == NULL) {
printf("wsmux_getmux: no memory for mux %d\n", n);
- return (NULL);
+ return NULL;
}
wsmuxdevs = new;
- for (; i < nwsmux; i++)
- wsmuxdevs[i] = NULL;
+ nwsmux = n + 1;
}
sc = wsmuxdevs[n];
Home |
Main Index |
Thread Index |
Old Index