tech-kern archive

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

Re: suprious reboot on netbsd-6:i386 with PAE



On Thu, Dec 05, 2013 at 05:57:06PM +0100, Wolfgang Solfrank wrote:
> Yes, that's what I was trying to hint at. Here the m_len
> does include the terminating '\0' byte, so it should be
> something like (untested):

Attached is third version, which seems to work fine at mine

-- 
Emmanuel Dreyfus
manu%netbsd.org@localhost
Index: sys/kern/uipc_usrreq.c
===================================================================
RCS file: /cvsroot/src/sys/kern/uipc_usrreq.c,v
retrieving revision 1.148
diff -U4 -r1.148 uipc_usrreq.c
--- sys/kern/uipc_usrreq.c      29 Oct 2013 09:53:51 -0000      1.148
+++ sys/kern/uipc_usrreq.c      6 Dec 2013 04:30:49 -0000
@@ -347,17 +347,20 @@
                                sun = unp->unp_addr;
                }
                if (sun == NULL)
                        sun = &sun_noname;
-               nam->m_len = sun->sun_len;
+
+               nam->m_len = sun->sun_len + 1;  /* +1 for trailing \0 */
+
                if (nam->m_len > MLEN && !ext) {
                        sounlock(so);
                        MEXTMALLOC(nam, MAXPATHLEN * 2, M_WAITOK);
                        solock(so);
                        ext = true;
                } else {
                        KASSERT(nam->m_len <= MAXPATHLEN * 2);
                        memcpy(mtod(nam, void *), sun, (size_t)nam->m_len);
+                       mtod(nam, char *)[nam->m_len - 1] = '\0'; 
                        break;
                }
        }
 }
@@ -894,12 +897,11 @@
 static struct sockaddr_un *
 makeun(struct mbuf *nam, size_t *addrlen) {
        struct sockaddr_un *sun;
 
-       *addrlen = nam->m_len + 1;
+       *addrlen = nam->m_len;
        sun = malloc(*addrlen, M_SONAME, M_WAITOK);
        m_copydata(nam, 0, nam->m_len, (void *)sun);
-       *(((char *)sun) + nam->m_len) = '\0';
        sun->sun_len = strlen(sun->sun_path) +
            offsetof(struct sockaddr_un, sun_path);
        return sun;
 }


Home | Main Index | Thread Index | Old Index