Applied part of [ 1575767 ] Init/size/check fixes for sockets

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
This commit is contained in:
Robert Roebling
2006-10-13 09:00:06 +00:00
parent ddd5387387
commit 8913c40c32
2 changed files with 32 additions and 3 deletions

View File

@@ -356,15 +356,17 @@ wxTCPConnection::wxTCPConnection(wxChar *buffer, int size)
wxTCPConnection::~wxTCPConnection () wxTCPConnection::~wxTCPConnection ()
{ {
Disconnect(); Disconnect();
wxDELETE(m_codeci);
wxDELETE(m_codeco);
wxDELETE(m_sockstrm);
if (m_sock) if (m_sock)
{ {
m_sock->SetClientData(NULL); m_sock->SetClientData(NULL);
m_sock->Destroy(); m_sock->Destroy();
} }
/* Delete after destroy */
wxDELETE(m_codeci);
wxDELETE(m_codeco);
wxDELETE(m_sockstrm);
} }
void wxTCPConnection::Compress(bool WXUNUSED(on)) void wxTCPConnection::Compress(bool WXUNUSED(on))
@@ -424,6 +426,7 @@ wxChar *wxTCPConnection::Request (const wxString& item, int *size, wxIPCFormat f
size_t s; size_t s;
s = m_codeci->Read32(); s = m_codeci->Read32();
wxChar *data = GetBufferAtLeast( s ); wxChar *data = GetBufferAtLeast( s );
wxASSERT_MSG(data != NULL, wxASSERT_MSG(data != NULL,
_T("Buffer too small in wxTCPConnection::Request") ); _T("Buffer too small in wxTCPConnection::Request") );
@@ -521,6 +524,9 @@ END_EVENT_TABLE()
void wxTCPEventHandler::Client_OnRequest(wxSocketEvent &event) void wxTCPEventHandler::Client_OnRequest(wxSocketEvent &event)
{ {
wxSocketBase *sock = event.GetSocket(); wxSocketBase *sock = event.GetSocket();
if (!sock) { /* No socket, no glory */
return ;
}
wxSocketNotify evt = event.GetSocketEvent(); wxSocketNotify evt = event.GetSocketEvent();
wxTCPConnection *connection = (wxTCPConnection *)(sock->GetClientData()); wxTCPConnection *connection = (wxTCPConnection *)(sock->GetClientData());
@@ -559,6 +565,7 @@ void wxTCPEventHandler::Client_OnRequest(wxSocketEvent &event)
format = (wxIPCFormat)codeci->Read8(); format = (wxIPCFormat)codeci->Read8();
size = codeci->Read32(); size = codeci->Read32();
data = connection->GetBufferAtLeast( size ); data = connection->GetBufferAtLeast( size );
wxASSERT_MSG(data != NULL, wxASSERT_MSG(data != NULL,
_T("Buffer too small in wxTCPEventHandler::Client_OnRequest") ); _T("Buffer too small in wxTCPEventHandler::Client_OnRequest") );
@@ -670,6 +677,9 @@ void wxTCPEventHandler::Client_OnRequest(wxSocketEvent &event)
void wxTCPEventHandler::Server_OnRequest(wxSocketEvent &event) void wxTCPEventHandler::Server_OnRequest(wxSocketEvent &event)
{ {
wxSocketServer *server = (wxSocketServer *) event.GetSocket(); wxSocketServer *server = (wxSocketServer *) event.GetSocket();
if (!server) { /* No server, Then exit */
return ;
}
wxTCPServer *ipcserv = (wxTCPServer *) server->GetClientData(); wxTCPServer *ipcserv = (wxTCPServer *) server->GetClientData();
// This socket is being deleted; skip this event // 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 // Accept the connection, getting a new socket
wxSocketBase *sock = server->Accept(); wxSocketBase *sock = server->Accept();
if (!sock) { /* No socket, no glory */
return ;
}
if (!sock->Ok()) if (!sock->Ok())
{ {
sock->Destroy(); sock->Destroy();

View File

@@ -371,6 +371,11 @@ char wxStreamBuffer::GetChar()
size_t wxStreamBuffer::Read(void *buffer, size_t size) 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 // lasterror is reset before all new IO calls
if ( m_stream ) if ( m_stream )
m_stream->Reset(); m_stream->Reset();
@@ -447,6 +452,8 @@ size_t wxStreamBuffer::Read(wxStreamBuffer *dbuf)
size_t wxStreamBuffer::Write(const void *buffer, size_t size) 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) if (m_stream)
{ {
// lasterror is reset before all new IO calls // 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) 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) if (!m_wback)
return 0; 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) 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 ) if ( m_lasterror != wxSTREAM_NO_ERROR && m_lasterror != wxSTREAM_EOF )
{ {
// can't operate on this stream until the error is cleared // 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) wxInputStream& wxInputStream::Read(void *buf, size_t size)
{ {
wxASSERT_MSG( buf, _T("Warning: Null pointer is about to be read") );
char *p = (char *)buf; char *p = (char *)buf;
m_lastcount = 0; m_lastcount = 0;