[ros-diffs] [gvg] 20316: Checking memory allocation return values helps prevent crashes

gvg at svn.reactos.com gvg at svn.reactos.com
Fri Dec 23 21:48:02 CET 2005


Checking memory allocation return values helps prevent crashes
Modified:
trunk/reactos/drivers/lib/oskittcp/include/freebsd/src/sys/sys/mbuf.h
Modified: trunk/reactos/drivers/lib/oskittcp/oskittcp/ip_output.c
  _____  

Modified:
trunk/reactos/drivers/lib/oskittcp/include/freebsd/src/sys/sys/mbuf.h
---
trunk/reactos/drivers/lib/oskittcp/include/freebsd/src/sys/sys/mbuf.h
2005-12-23 20:46:48 UTC (rev 20315)
+++
trunk/reactos/drivers/lib/oskittcp/include/freebsd/src/sys/sys/mbuf.h
2005-12-23 20:47:54 UTC (rev 20316)
@@ -304,9 +304,12 @@

 #ifdef __REACTOS__
 #define MCLGET(m, how) { \
           OS_DbgPrint(OSK_MID_TRACE,("(MCLGET) m = %x\n", m)); \
-          (m)->m_data = (m)->m_ext.ext_buf = malloc(MCLBYTES); \
-          (m)->m_flags |= M_EXT; \
-          (m)->m_ext.ext_size = MCLBYTES; \
+          (m)->m_ext.ext_buf = malloc(MCLBYTES); \
+	  if ((m)->m_ext.ext_buf != NULL) { \
+              (m)->m_data = (m)->m_ext.ext_buf; \
+              (m)->m_flags |= M_EXT; \
+              (m)->m_ext.ext_size = MCLBYTES; \
+          } \
         }
 
 #define MCLFREE(p) { \
  _____  

Modified: trunk/reactos/drivers/lib/oskittcp/oskittcp/ip_output.c
--- trunk/reactos/drivers/lib/oskittcp/oskittcp/ip_output.c
2005-12-23 20:46:48 UTC (rev 20315)
+++ trunk/reactos/drivers/lib/oskittcp/oskittcp/ip_output.c
2005-12-23 20:47:54 UTC (rev 20316)
@@ -366,8 +366,17 @@

 #ifdef __REACTOS__
 	    if( OtcpEvent.PacketSend ) {
 		struct mbuf *new_m;
-		MGET( new_m, M_DONTWAIT, 0 );
+		new_m = m_get( M_DONTWAIT, 0 );
+		if ( NULL == new_m ) {
+		    error = ENOBUFS;
+		    goto done;
+		}
 		MCLGET( new_m, M_DONTWAIT );
+		if (0 == (new_m->m_flags & M_EXT)) {
+		    m_free( new_m );
+		    error = ENOBUFS;
+		    goto done;
+		}
 		m_copydata( m, 0, htons(ip->ip_len), new_m->m_data );
 		new_m->m_len = htons(ip->ip_len);
 		error = OtcpEvent.PacketSend( OtcpEvent.ClientData,
@@ -498,7 +507,16 @@
 	if( error == 0 && OtcpEvent.PacketSend ) {
 	    struct mbuf *new_m;
 	    MGET( new_m, M_DONTWAIT, 0 );
+	    if ( NULL == new_m ) {
+		error = ENOBUFS;
+		goto done;
+	    }
 	    MCLGET( new_m, M_DONTWAIT );
+	    if (0 == (new_m->m_flags & M_EXT)) {
+		m_free( new_m );
+		error = ENOBUFS;
+		goto done;
+	    }
 	    m_copydata( m, 0, htons(ip->ip_len), new_m->m_data );
 	    new_m->m_len = htons(ip->ip_len);
 	    error = OtcpEvent.PacketSend( OtcpEvent.ClientData,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.reactos.org/pipermail/ros-diffs/attachments/20051223/f2eb7903/attachment.html


More information about the Ros-diffs mailing list