Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern In adjust_rights() Use CMSG_SPACE() to calculate th...



details:   https://anonhg.NetBSD.org/src/rev/d4c165d2c46b
branches:  trunk
changeset: 583994:d4c165d2c46b
user:      martin <martin%NetBSD.org@localhost>
date:      Sat Sep 03 22:48:35 2005 +0000

description:
In adjust_rights() Use CMSG_SPACE() to calculate the number of
filedescriptors passed in this message - the counterpart in
unp_externalize does this as well.

Note that CMSG_SPACE(0) does not make sense, since it does not invoke
the alignment magic - so use CMSG_SPACE(sizeof(int)) and adjust the
calculated total later.

This fixes the postfix conection cache for 64bit platforms. Previously
the number of passed filed descriptors (nfds) would have been
calculeted too high, causing the fdrelease() of uninitialized junk.

diffstat:

 sys/kern/uipc_syscalls.c |  7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diffs (28 lines):

diff -r bd3a7f26c764 -r d4c165d2c46b sys/kern/uipc_syscalls.c
--- a/sys/kern/uipc_syscalls.c  Sat Sep 03 20:38:07 2005 +0000
+++ b/sys/kern/uipc_syscalls.c  Sat Sep 03 22:48:35 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_syscalls.c,v 1.93 2005/09/03 19:44:20 martin Exp $        */
+/*     $NetBSD: uipc_syscalls.c,v 1.94 2005/09/03 22:48:35 martin Exp $        */
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1990, 1993
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.93 2005/09/03 19:44:20 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.94 2005/09/03 22:48:35 martin Exp $");
 
 #include "opt_ktrace.h"
 #include "opt_pipe.h"
@@ -658,7 +658,8 @@
        int nok;
        int *fdv;
 
-       nfd = (m->m_len - CMSG_LEN(0)) / sizeof(int);
+       nfd = m->m_len < CMSG_SPACE(sizeof(int)) ? 0
+           : (m->m_len - CMSG_SPACE(sizeof(int))) / sizeof(int) + 1;
        nok = (len < CMSG_LEN(0)) ? 0 : ((len - CMSG_LEN(0)) / sizeof(int));
        fdv = (int *) CMSG_DATA(mtod(m,struct cmsghdr *));
        for (i = nok; i < nfd; i++)



Home | Main Index | Thread Index | Old Index