From fc59b695ea1013ebbc2510dcaf2c9a379fe6efcc Mon Sep 17 00:00:00 2001 From: tedu Date: Tue, 19 Jul 2016 05:30:48 +0000 Subject: [PATCH] instead of messing about with pointer arithmetic, add an empty array to the end of the defer structure. solves sizing and alignment concerns. --- sys/kern/uipc_usrreq.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index ea4c716b0bb..775aedf432e 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_usrreq.c,v 1.99 2016/07/12 14:28:02 tedu Exp $ */ +/* $OpenBSD: uipc_usrreq.c,v 1.100 2016/07/19 05:30:48 tedu Exp $ */ /* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */ /* @@ -64,6 +64,7 @@ struct unp_deferral { SLIST_ENTRY(unp_deferral) ud_link; int ud_n; /* followed by ud_n struct file * pointers */ + struct file *ud_fp[]; }; /* list of sets of files that were sent over sockets that are now closed */ @@ -896,8 +897,7 @@ unp_gc(void *arg __unused) while ((defer = SLIST_FIRST(&unp_deferred)) != NULL) { SLIST_REMOVE_HEAD(&unp_deferred, ud_link); for (i = 0; i < defer->ud_n; i++) { - memcpy(&fp, &((struct file **)(defer + 1))[i], - sizeof(fp)); + fp = defer->ud_fp[i]; if (fp == NULL) continue; FREF(fp); @@ -1059,7 +1059,7 @@ unp_discard(struct file **rp, int nfds) /* copy the file pointers to a deferral structure */ defer = malloc(sizeof(*defer) + sizeof(*rp) * nfds, M_TEMP, M_WAITOK); defer->ud_n = nfds; - memcpy(defer + 1, rp, sizeof(*rp) * nfds); + memcpy(&defer->ud_fp[0], rp, sizeof(*rp) * nfds); memset(rp, 0, sizeof(*rp) * nfds); SLIST_INSERT_HEAD(&unp_deferred, defer, ud_link); -- 2.20.1