Add missing memory check in port table handling. Patch based on

PR bin/9080 by Jun-ichiro itojun Hagino
This commit is contained in:
tron 1999-12-31 12:58:12 +00:00
parent 18c5f3d5f1
commit a3045c188e
1 changed files with 12 additions and 9 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: netcmds.c,v 1.10 1999/12/20 04:06:25 jwise Exp $ */ /* $NetBSD: netcmds.c,v 1.11 1999/12/31 12:58:12 tron Exp $ */
/*- /*-
* Copyright (c) 1980, 1992, 1993 * Copyright (c) 1980, 1992, 1993
@ -38,7 +38,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)netcmds.c 8.1 (Berkeley) 6/6/93"; static char sccsid[] = "@(#)netcmds.c 8.1 (Berkeley) 6/6/93";
#endif #endif
__RCSID("$NetBSD: netcmds.c,v 1.10 1999/12/20 04:06:25 jwise Exp $"); __RCSID("$NetBSD: netcmds.c,v 1.11 1999/12/31 12:58:12 tron Exp $");
#endif /* not lint */ #endif /* not lint */
/* /*
@ -210,7 +210,7 @@ showprotos()
static struct pitem { static struct pitem {
long port; long port;
int onoff; int onoff;
} *ports; } *ports = NULL;
static int static int
selectport(port, onoff) selectport(port, onoff)
@ -220,9 +220,10 @@ selectport(port, onoff)
struct pitem *p; struct pitem *p;
if (port == -1) { if (port == -1) {
if (ports == 0) if (ports == NULL)
return (0); return (0);
free((char *)ports), ports = 0; free(ports);
ports = NULL;
nports = 0; nports = 0;
return (1); return (1);
} }
@ -231,10 +232,12 @@ selectport(port, onoff)
p->onoff = onoff; p->onoff = onoff;
return (0); return (0);
} }
if (nports == 0) p = (struct pitem *)realloc(ports, (nports+1)*sizeof (*p));
ports = (struct pitem *)malloc(sizeof (*p)); if (p == NULL) {
else error("malloc failed");
ports = (struct pitem *)realloc(ports, (nports+1)*sizeof (*p)); die(0);
}
ports = p;
p = &ports[nports++]; p = &ports[nports++];
p->port = port; p->port = port;
p->onoff = onoff; p->onoff = onoff;