]> git.saurik.com Git - wxWidgets.git/commitdiff
Applied part of [ 1575767 ] Init/size/check fixes for sockets
authorRobert Roebling <robert@roebling.de>
Fri, 13 Oct 2006 09:00:06 +0000 (09:00 +0000)
committerRobert Roebling <robert@roebling.de>
Fri, 13 Oct 2006 09:00:06 +0000 (09:00 +0000)
Left out the time out parameter change.
Left out the improper test for arbitrary too large value upon
read failure.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41982 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/sckipc.cpp
src/common/stream.cpp

index f2b33bb2e2ad3b8898bac698d0011e3508adb379..3b03e2de76f10366f6e442e261e19f3e6a0db596 100644 (file)
@@ -356,15 +356,17 @@ wxTCPConnection::wxTCPConnection(wxChar *buffer, int size)
 wxTCPConnection::~wxTCPConnection ()
 {
   Disconnect();
-  wxDELETE(m_codeci);
-  wxDELETE(m_codeco);
-  wxDELETE(m_sockstrm);
 
   if (m_sock)
   {
     m_sock->SetClientData(NULL);
     m_sock->Destroy();
   }
+
+  /* Delete after destroy */
+  wxDELETE(m_codeci);
+  wxDELETE(m_codeco);
+  wxDELETE(m_sockstrm);
 }
 
 void wxTCPConnection::Compress(bool WXUNUSED(on))
@@ -424,6 +426,7 @@ wxChar *wxTCPConnection::Request (const wxString& item, int *size, wxIPCFormat f
     size_t s;
 
     s = m_codeci->Read32();
+
     wxChar *data = GetBufferAtLeast( s );
     wxASSERT_MSG(data != NULL,
                  _T("Buffer too small in wxTCPConnection::Request") );
@@ -521,6 +524,9 @@ END_EVENT_TABLE()
 void wxTCPEventHandler::Client_OnRequest(wxSocketEvent &event)
 {
   wxSocketBase *sock = event.GetSocket();
+  if (!sock) {         /* No socket, no glory */
+    return ;
+  }
   wxSocketNotify evt = event.GetSocketEvent();
   wxTCPConnection *connection = (wxTCPConnection *)(sock->GetClientData());
 
@@ -559,6 +565,7 @@ void wxTCPEventHandler::Client_OnRequest(wxSocketEvent &event)
 
     format = (wxIPCFormat)codeci->Read8();
     size = codeci->Read32();
+    
     data = connection->GetBufferAtLeast( size );
     wxASSERT_MSG(data != NULL,
                  _T("Buffer too small in wxTCPEventHandler::Client_OnRequest") );
@@ -670,6 +677,9 @@ void wxTCPEventHandler::Client_OnRequest(wxSocketEvent &event)
 void wxTCPEventHandler::Server_OnRequest(wxSocketEvent &event)
 {
   wxSocketServer *server = (wxSocketServer *) event.GetSocket();
+  if (!server) {               /* No server, Then exit */
+         return ;
+  }
   wxTCPServer *ipcserv = (wxTCPServer *) server->GetClientData();
 
   // This socket is being deleted; skip this event
@@ -681,6 +691,9 @@ void wxTCPEventHandler::Server_OnRequest(wxSocketEvent &event)
 
   // Accept the connection, getting a new socket
   wxSocketBase *sock = server->Accept();
+  if (!sock) {         /* No socket, no glory */
+         return ;
+  }
   if (!sock->Ok())
   {
     sock->Destroy();
index f13da0d3d8af6a7e542f04eacde4bedfe4e82e8d..a0ce91c79df019c4ba89c9086c51a95ff219403f 100644 (file)
@@ -371,6 +371,11 @@ char wxStreamBuffer::GetChar()
 
 size_t wxStreamBuffer::Read(void *buffer, size_t size)
 {
+    wxASSERT_MSG( buffer, _T("Warning: Null pointer is about to be used") );
+
+    /* Clear buffer first */
+    memset(buffer, 0x00, size);
+
     // lasterror is reset before all new IO calls
     if ( m_stream )
         m_stream->Reset();
@@ -447,6 +452,8 @@ size_t wxStreamBuffer::Read(wxStreamBuffer *dbuf)
 
 size_t wxStreamBuffer::Write(const void *buffer, size_t size)
 {
+    wxASSERT_MSG( buffer, _T("Warning: Null pointer is about to be send") );
+
     if (m_stream)
     {
         // lasterror is reset before all new IO calls
@@ -741,6 +748,11 @@ char *wxInputStream::AllocSpaceWBack(size_t needed_size)
 
 size_t wxInputStream::GetWBack(void *buf, size_t size)
 {
+    wxASSERT_MSG( buf, _T("Warning: Null pointer is about to be used") );
+
+    /* Clear buffer first */
+    memset(buf, 0x00, size);
+
     if (!m_wback)
         return 0;
 
@@ -772,6 +784,8 @@ size_t wxInputStream::GetWBack(void *buf, size_t size)
 
 size_t wxInputStream::Ungetch(const void *buf, size_t bufsize)
 {
+    wxASSERT_MSG( buf, _T("Warning: Null pointer is about to be used in Ungetch()") );
+
     if ( m_lasterror != wxSTREAM_NO_ERROR && m_lasterror != wxSTREAM_EOF )
     {
         // can't operate on this stream until the error is cleared
@@ -804,6 +818,8 @@ char wxInputStream::GetC()
 
 wxInputStream& wxInputStream::Read(void *buf, size_t size)
 {
+    wxASSERT_MSG( buf, _T("Warning: Null pointer is about to be read") );
+
     char *p = (char *)buf;
     m_lastcount = 0;