summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2013-04-16 12:15:56 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2013-04-16 12:15:56 +0000
commit3347a3c7710e465572b8e5c8e01e94072b7269b3 (patch)
tree001cd87335feeba61b0f5786a5e9238b2cfbaf65
parentd72a172b8b545604756d7d9fc94d3c95a2cd4d7f (diff)
Replace a realloc() + memcpy() with calloc() + memcpy().
We don't need to zero pfd but using calloc() gets us overflow protection for free. OK chl@ deraadt@
-rw-r--r--lib/libc/rpc/svc_run.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/lib/libc/rpc/svc_run.c b/lib/libc/rpc/svc_run.c
index 07af0a16367..caab04195cf 100644
--- a/lib/libc/rpc/svc_run.c
+++ b/lib/libc/rpc/svc_run.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: svc_run.c,v 1.19 2010/09/01 14:43:34 millert Exp $ */
+/* $OpenBSD: svc_run.c,v 1.20 2013/04/16 12:15:55 millert Exp $ */
/*
* Copyright (c) 2010, Oracle America, Inc.
@@ -45,18 +45,17 @@
void
svc_run(void)
{
- struct pollfd *pfd = NULL, *newp;
+ struct pollfd *pfd = NULL;
int nready, saved_max_pollfd = 0;
for (;;) {
if (svc_max_pollfd > saved_max_pollfd) {
- newp = realloc(pfd, sizeof(*pfd) * svc_max_pollfd);
- if (newp == NULL) {
- free(pfd);
+ free(pfd);
+ pfd = calloc(sizeof(*pfd), svc_max_pollfd);
+ if (pfd == NULL) {
perror("svc_run"); /* XXX */
return; /* XXX */
}
- pfd = newp;
saved_max_pollfd = svc_max_pollfd;
}
memcpy(pfd, svc_pollfd, sizeof(*pfd) * svc_max_pollfd);