Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/rpcbind rpcbind(8): Use reallocarr, fix reallocatio...
details: https://anonhg.NetBSD.org/src/rev/d1e3cba7223b
branches: trunk
changeset: 990558:d1e3cba7223b
user: nia <nia%NetBSD.org@localhost>
date: Sat Oct 30 11:04:48 2021 +0000
description:
rpcbind(8): Use reallocarr, fix reallocation logic.
In my_svc_run(), only update the fd count _after_ the allocation
succeeds (which may be after waiting in the loop). This function
previously tried to go to a label that doesn't exist. I wonder why
GCC didn't catch this before but does now.
diffstat:
usr.sbin/rpcbind/rpcb_svc_com.c | 24 ++++++++++++------------
usr.sbin/rpcbind/rpcbind.c | 10 +++-------
2 files changed, 15 insertions(+), 19 deletions(-)
diffs (87 lines):
diff -r fd30b1f87077 -r d1e3cba7223b usr.sbin/rpcbind/rpcb_svc_com.c
--- a/usr.sbin/rpcbind/rpcb_svc_com.c Sat Oct 30 10:59:07 2021 +0000
+++ b/usr.sbin/rpcbind/rpcb_svc_com.c Sat Oct 30 11:04:48 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rpcb_svc_com.c,v 1.25 2021/04/13 05:58:45 mrg Exp $ */
+/* $NetBSD: rpcb_svc_com.c,v 1.26 2021/10/30 11:04:48 nia Exp $ */
/* $FreeBSD: head/usr.sbin/rpcbind/rpcb_svc_com.c 301770 2016-06-09 22:25:00Z pfg $ */
/*-
@@ -1106,7 +1106,7 @@
{
size_t nfds;
struct pollfd *pollfds;
- int npollfds;
+ int npollfds, newfdcount;
int poll_ret, check_ret;
int n, *m;
#ifdef SVC_RUN_DEBUG
@@ -1118,19 +1118,19 @@
npollfds = 0;
for (;;) {
- if (svc_fdset_getsize(0) != npollfds) {
- npollfds = svc_fdset_getsize(0);
- pollfds = realloc(pollfds, npollfds * sizeof(*pollfds));
+ newfdcount = svc_fdset_getsize(0);
+ if (newfdcount != npollfds) {
+ if (reallocarr(&pollfds,
+ newfdcount, sizeof(*pollfds)) != 0) {
+ syslog(LOG_ERR, "Cannot allocate pollfds");
+ sleep(1);
+ continue;
+ }
+ npollfds = newfdcount;
}
p = pollfds;
- if (p == NULL) {
-out:
- syslog(LOG_ERR, "Cannot allocate pollfds");
- sleep(1);
- continue;
- }
if ((m = svc_fdset_getmax()) == NULL)
- goto out;
+ break;
for (n = 0; n <= *m; n++) {
if (svc_fdset_isset(n)) {
p->fd = n;
diff -r fd30b1f87077 -r d1e3cba7223b usr.sbin/rpcbind/rpcbind.c
--- a/usr.sbin/rpcbind/rpcbind.c Sat Oct 30 10:59:07 2021 +0000
+++ b/usr.sbin/rpcbind/rpcbind.c Sat Oct 30 11:04:48 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rpcbind.c,v 1.30 2021/03/07 00:23:06 christos Exp $ */
+/* $NetBSD: rpcbind.c,v 1.31 2021/10/30 11:04:48 nia Exp $ */
/*-
* Copyright (c) 2009, Sun Microsystems, Inc.
@@ -362,18 +362,15 @@
}
if (strcmp(nconf->nc_netid, "local") != 0) {
- char **nhp;
/*
* If no hosts were specified, just bind to INADDR_ANY.
* Otherwise make sure 127.0.0.1 is added to the list.
*/
nhostsbak = nhosts + 1;
- nhp = realloc(hosts, nhostsbak * sizeof(*hosts));
- if (nhp == NULL) {
+ if (reallocarr(&hosts, nhostsbak, sizeof(*hosts)) != 0) {
syslog(LOG_ERR, "Can't grow hosts array");
return 1;
}
- hosts = nhp;
if (nhostsbak == 1)
hosts[0] = __UNCONST("*");
else {
@@ -903,8 +900,7 @@
break;
case 'h':
++nhosts;
- hosts = realloc(hosts, nhosts * sizeof(*hosts));
- if (hosts == NULL)
+ if (reallocarr(&hosts, nhosts, sizeof(*hosts)) != 0)
err(EXIT_FAILURE, "Can't allocate host array");
hosts[nhosts - 1] = strdup(optarg);
if (hosts[nhosts - 1] == NULL)
Home |
Main Index |
Thread Index |
Old Index