diff options
author | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2003-10-16 03:39:13 +0000 |
---|---|---|
committer | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2003-10-16 03:39:13 +0000 |
commit | 54d475c67b98d1deaa48ada27913141981d6cacf (patch) | |
tree | f5800c29e03913a2f757ebd3f884a3534b104e89 /usr.sbin/lpr | |
parent | 137aeae781b7de7306f8f0c06c3d403a92f98ce0 (diff) |
safer realloc. deraadt ok
Diffstat (limited to 'usr.sbin/lpr')
-rw-r--r-- | usr.sbin/lpr/lpd/lpd.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/usr.sbin/lpr/lpd/lpd.c b/usr.sbin/lpr/lpd/lpd.c index cf120480967..aba9a88e3c6 100644 --- a/usr.sbin/lpr/lpd/lpd.c +++ b/usr.sbin/lpr/lpd/lpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lpd.c,v 1.41 2003/09/26 06:01:42 pvalchev Exp $ */ +/* $OpenBSD: lpd.c,v 1.42 2003/10/16 03:39:12 itojun Exp $ */ /* $NetBSD: lpd.c,v 1.33 2002/01/21 14:42:29 wiz Exp $ */ /* @@ -41,7 +41,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)lpd.c 8.7 (Berkeley) 5/10/95"; #else -static const char rcsid[] = "$OpenBSD: lpd.c,v 1.41 2003/09/26 06:01:42 pvalchev Exp $"; +static const char rcsid[] = "$OpenBSD: lpd.c,v 1.42 2003/10/16 03:39:12 itojun Exp $"; #endif #endif /* not lint */ @@ -786,7 +786,7 @@ int * socksetup(int af, int options, const char *port) { struct addrinfo hints, *res, *r; - int error, maxs = 0, *s, *socks = NULL, blidx = 0; + int error, maxs = 0, *s, *socks = NULL, *newsocks, blidx = 0; const int on = 1; do { @@ -812,8 +812,15 @@ socksetup(int af, int options, const char *port) socks = malloc((maxs + 1) * sizeof(int)); if (socks) *socks = 0; /* num of sockets ctr at start */ - } else - socks = realloc(socks, (maxs + 1) * sizeof(int)); + } else { + newsocks = realloc(socks, (maxs + 1) * sizeof(int)); + if (newsocks) + socks = newsocks; + else { + free(socks); + socks = NULL; + } + } if (!socks) { syslog(LOG_ERR, "couldn't allocate memory for sockets"); mcleanup(0); |