Skip to contentSkip to conversation

Fix crash due to faulty realloc logic in slirp/mbuf.c

PATCH New Ed Swierk 1 participant 1 message May 1, 2006

lore
Share & tools
lore

Ed Swierk

author
#0 lore raw

PATCH 1/1 Fix crash due to faulty realloc logic in slirp/mbuf.c

The attached patch fixes a bug in the slirp memory management code. m_inc() is called during IP reassembly for IP datagrams greater than 4 KB, as arises with NFS. Currently the code assumes that realloc() always resizes the buffer without moving it; if the buffer is moved, the m_data pointer is left pointing to an invalid location. The bug causes qemu to crash when there is any significant amount of NFS traffic.

The patch restores some commented-out code that updates m_data correctly.

--Ed

slirp/mbuf.c +4 -3
diff -BurN qemu-snapshot-2006-03-27_23.orig/slirp/mbuf.c qemu-snapshot-2006-03-27_23/slirp/mbuf.c
@@ -146,18 +146,19 @@
         struct mbuf *m;
         int size;
 {
+	int datasize;
+
 	/* some compiles throw up on gotos.  This one we can fake. */
         if(m->m_size>size) return;
 
         if (m->m_flags & M_EXT) {
-	  /* datasize = m->m_data - m->m_ext; */
+	  datasize = m->m_data - m->m_ext;
 	  m->m_ext = (char *)realloc(m->m_ext,size);
 /*		if (m->m_ext == NULL)
  *			return (struct mbuf *)NULL;
  */		
-	  /* m->m_data = m->m_ext + datasize; */
+	  m->m_data = m->m_ext + datasize;
         } else {
-	  int datasize;
 	  char *dat;
 	  datasize = m->m_data - m->m_dat;
 	  dat = (char *)malloc(size);