summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2003-09-26 03:30:00 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2003-09-26 03:30:00 +0000
commitefe57bfef62b34258d5f4fb4d793ccb59ad3a956 (patch)
treefebe219d3e88c897902d13bd96fd320ff8e3e84b
parent8cdf209a4fa8c7940fe805374c1bd7096ea0c8a5 (diff)
realloc properly; ok jason
-rw-r--r--sbin/brconfig/brconfig.c44
1 files changed, 28 insertions, 16 deletions
diff --git a/sbin/brconfig/brconfig.c b/sbin/brconfig/brconfig.c
index ea9e96f4d46..6747571d94a 100644
--- a/sbin/brconfig/brconfig.c
+++ b/sbin/brconfig/brconfig.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: brconfig.c,v 1.26 2003/06/25 09:44:55 henning Exp $ */
+/* $OpenBSD: brconfig.c,v 1.27 2003/09/26 03:29:59 deraadt Exp $ */
/*
* Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net)
@@ -474,16 +474,19 @@ bridge_ifclrflag(int s, char *brdg, char *ifsname, u_int32_t flag)
int
bridge_show_all(int s)
{
- char *inbuf = NULL;
+ char *inbuf = NULL, *inb;
struct ifconf ifc;
struct ifreq *ifrp, ifreq;
int len = 8192, i;
while (1) {
ifc.ifc_len = len;
- ifc.ifc_buf = inbuf = realloc(inbuf, len);
- if (inbuf == NULL)
+ inb = realloc(inbuf, len);
+ if (inb == NULL) {
+ free(inbuf);
err(1, "malloc");
+ }
+ ifc.ifc_buf = inbuf = inb;
if (ioctl(s, SIOCGIFCONF, &ifc) < 0)
err(1, "ioctl(SIOCGIFCONF)");
if (ifc.ifc_len + sizeof(struct ifreq) < len)
@@ -631,14 +634,17 @@ bridge_list(int s, char *brdg, char *delim)
struct ifbreq *reqp;
struct ifbifconf bifc;
int i, len = 8192;
- char buf[sizeof(reqp->ifbr_ifsname) + 1], *inbuf = NULL;
+ char buf[sizeof(reqp->ifbr_ifsname) + 1], *inbuf = NULL, *inb;
while (1) {
- strlcpy(bifc.ifbic_name, brdg, sizeof(bifc.ifbic_name));
bifc.ifbic_len = len;
- bifc.ifbic_buf = inbuf = realloc(inbuf, len);
- if (inbuf == NULL)
+ inb = realloc(inbuf, len);
+ if (inb == NULL) {
+ free(inbuf);
err(1, "malloc");
+ }
+ bifc.ifbic_buf = inbuf = inb;
+ strlcpy(bifc.ifbic_name, brdg, sizeof(bifc.ifbic_name));
if (ioctl(s, SIOCBRDGIFS, &bifc) < 0)
err(1, "%s", brdg);
if (bifc.ifbic_len + sizeof(*reqp) < len)
@@ -978,15 +984,18 @@ bridge_addrs(int s, char *brdg, char *delim)
{
struct ifbaconf ifbac;
struct ifbareq *ifba;
- char *inbuf = NULL, buf[sizeof(ifba->ifba_ifsname) + 1];
+ char *inbuf = NULL, buf[sizeof(ifba->ifba_ifsname) + 1], *inb;
int i, len = 8192;
while (1) {
ifbac.ifbac_len = len;
- ifbac.ifbac_buf = inbuf = realloc(inbuf, len);
- strlcpy(ifbac.ifbac_name, brdg, sizeof(ifbac.ifbac_name));
- if (inbuf == NULL)
+ inb = realloc(inbuf, len);
+ if (inb == NULL) {
+ free(inbuf);
err(EX_IOERR, "malloc");
+ }
+ ifbac.ifbac_buf = inbuf = inb;
+ strlcpy(ifbac.ifbac_name, brdg, sizeof(ifbac.ifbac_name));
if (ioctl(s, SIOCBRDGRTS, &ifbac) < 0) {
if (errno == ENETDOWN)
return (0);
@@ -1098,18 +1107,21 @@ bridge_flushrule(int s, char *brdg, char *ifname)
int
bridge_rules(int s, char *brdg, char *ifname, char *delim)
{
- char *inbuf = NULL;
+ char *inbuf = NULL, *inb;
struct ifbrlconf ifc;
struct ifbrlreq *ifrp, ifreq;
int len = 8192, i;
while (1) {
ifc.ifbrl_len = len;
- ifc.ifbrl_buf = inbuf = realloc(inbuf, len);
+ inb = realloc(inbuf, len);
+ if (inb == NULL) {
+ free(inbuf);
+ err(1, "malloc");
+ }
+ ifc.ifbrl_buf = inbuf = inb;
strlcpy(ifc.ifbrl_name, brdg, sizeof(ifc.ifbrl_name));
strlcpy(ifc.ifbrl_ifsname, ifname, sizeof(ifc.ifbrl_ifsname));
- if (inbuf == NULL)
- err(1, "malloc");
if (ioctl(s, SIOCBRDGGRL, &ifc) < 0)
err(1, "ioctl(SIOCBRDGGRL)");
if (ifc.ifbrl_len + sizeof(ifreq) < len)