Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Avoid kmem_alloc KASSERT for 0 byte allocation, whe...



details:   https://anonhg.NetBSD.org/src/rev/1a5d6741fbb4
branches:  trunk
changeset: 780239:1a5d6741fbb4
user:      njoly <njoly%NetBSD.org@localhost>
date:      Tue Jul 17 14:22:42 2012 +0000

description:
Avoid kmem_alloc KASSERT for 0 byte allocation, when tracing processes
that use empty messages with sendmsg/recvmsg.

diffstat:

 sys/kern/uipc_syscalls.c |  21 +++++++++++----------
 1 files changed, 11 insertions(+), 10 deletions(-)

diffs (72 lines):

diff -r e7c16ad46145 -r 1a5d6741fbb4 sys/kern/uipc_syscalls.c
--- a/sys/kern/uipc_syscalls.c  Tue Jul 17 10:33:46 2012 +0000
+++ b/sys/kern/uipc_syscalls.c  Tue Jul 17 14:22:42 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_syscalls.c,v 1.155 2012/06/22 18:26:35 christos Exp $     */
+/*     $NetBSD: uipc_syscalls.c,v 1.156 2012/07/17 14:22:42 njoly Exp $        */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.155 2012/06/22 18:26:35 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.156 2012/07/17 14:22:42 njoly Exp $");
 
 #include "opt_pipe.h"
 
@@ -604,7 +604,7 @@
                }
        }
 
-       if (ktrpoint(KTR_GENIO)) {
+       if (ktrpoint(KTR_GENIO) && iovsz > 0) {
                ktriov = kmem_alloc(iovsz, KM_SLEEP);
                memcpy(ktriov, auio.uio_iov, iovsz);
        }
@@ -634,9 +634,10 @@
                *retsize = len - auio.uio_resid;
 
 bad:
-       if (ktriov != NULL) {
+       if (ktrpoint(KTR_GENIO)) {
                ktrgeniov(s, UIO_WRITE, ktriov, *retsize, error);
-               kmem_free(ktriov, iovsz);
+               if (ktriov != NULL)
+                       kmem_free(ktriov, iovsz);
        }
 
        if (iov != aiov)
@@ -897,7 +898,7 @@
 do_sys_recvmsg_so(struct lwp *l, int s, struct socket *so, struct msghdr *mp,
     struct mbuf **from, struct mbuf **control, register_t *retsize)
 {
-       struct iovec    aiov[UIO_SMALLIOV], *iov = aiov, *tiov, *ktriov;
+       struct iovec    aiov[UIO_SMALLIOV], *iov = aiov, *tiov, *ktriov = NULL;
        struct uio      auio;
        size_t          len, iovsz;
        int             i, error;
@@ -947,8 +948,7 @@
                }
        }
 
-       ktriov = NULL;
-       if (ktrpoint(KTR_GENIO)) {
+       if (ktrpoint(KTR_GENIO) && iovsz > 0) {
                ktriov = kmem_alloc(iovsz, KM_SLEEP);
                memcpy(ktriov, auio.uio_iov, iovsz);
        }
@@ -964,9 +964,10 @@
                /* Some data transferred */
                error = 0;
 
-       if (ktriov != NULL) {
+       if (ktrpoint(KTR_GENIO)) {
                ktrgeniov(s, UIO_READ, ktriov, len, error);
-               kmem_free(ktriov, iovsz);
+               if (ktriov != NULL)
+                       kmem_free(ktriov, iovsz);
        }
 
        if (error != 0) {



Home | Main Index | Thread Index | Old Index