[bug 804] null pointer references in internet-stack

This commit is contained in:
Bill Roome
2010-02-09 22:03:57 -08:00
parent 8358e83e27
commit b993072a7a
3 changed files with 48 additions and 8 deletions

View File

@@ -482,6 +482,7 @@ Ipv4L3Protocol::Receive( Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t pr
socket->ForwardUp (packet, ipHeader, device);
}
NS_ASSERT_MSG (m_routingProtocol != 0, "Need a routing protocol object to process packets");
m_routingProtocol->RouteInput (packet, ipHeader, device,
MakeCallback (&Ipv4L3Protocol::IpForward, this),
MakeCallback (&Ipv4L3Protocol::IpMulticastForward, this),
@@ -609,7 +610,15 @@ Ipv4L3Protocol::Send (Ptr<Packet> packet,
Socket::SocketErrno errno_;
Ptr<NetDevice> oif (0); // unused for now
ipHeader = BuildHeader (source, destination, protocol, packet->GetSize (), ttl, mayFragment);
Ptr<Ipv4Route> newRoute = m_routingProtocol->RouteOutput (packet, ipHeader, oif, errno_);
Ptr<Ipv4Route> newRoute;
if (m_routingProtocol != 0)
{
newRoute = m_routingProtocol->RouteOutput (packet, ipHeader, oif, errno_);
}
else
{
NS_LOG_ERROR ("Ipv4L3Protocol::Send: m_routingProtocol == 0");
}
if (newRoute)
{
int32_t interface = GetInterfaceForDevice (newRoute->GetOutputDevice ());

View File

@@ -584,7 +584,15 @@ TcpL4Protocol::Send (Ptr<Packet> packet,
Socket::SocketErrno errno_;
Ptr<Ipv4Route> route;
Ptr<NetDevice> oif (0); //specify non-zero if bound to a source address
route = ipv4->GetRoutingProtocol ()->RouteOutput (packet, header, oif, errno_);
if (ipv4->GetRoutingProtocol () != 0)
{
route = ipv4->GetRoutingProtocol ()->RouteOutput (packet, header, oif, errno_);
}
else
{
NS_LOG_ERROR ("No IPV4 Routing Protocol");
route = 0;
}
ipv4->Send (packet, saddr, daddr, PROT_NUMBER, route);
}
}
@@ -623,7 +631,15 @@ TcpL4Protocol::SendPacket (Ptr<Packet> packet, const TcpHeader &outgoing,
header.SetProtocol (PROT_NUMBER);
Socket::SocketErrno errno_;
Ptr<Ipv4Route> route;
route = ipv4->GetRoutingProtocol ()->RouteOutput (packet, header, oif, errno_);
if (ipv4->GetRoutingProtocol () != 0)
{
route = ipv4->GetRoutingProtocol ()->RouteOutput (packet, header, oif, errno_);
}
else
{
NS_LOG_ERROR ("No IPV4 Routing Protocol");
route = 0;
}
ipv4->Send (packet, saddr, daddr, PROT_NUMBER, route);
}
else

View File

@@ -358,6 +358,7 @@ TcpSocketImpl::Connect (const Address & address)
NS_LOG_FUNCTION (this << address);
Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
NS_ASSERT (ipv4 != 0);
if (m_endPoint == 0)
{
@@ -772,11 +773,17 @@ void TcpSocketImpl::SendEmptyPacket (uint8_t flags)
Ptr<Packet> p = Create<Packet> ();
TcpHeader header;
if (m_endPoint == 0)
{
NS_LOG_WARN ("Failed to send empty packet due to null endpoint");
return;
}
if (flags & TcpHeader::FIN)
{
flags |= TcpHeader::ACK;
}
header.SetFlags (flags);
header.SetSequenceNumber (m_nextTxSequence);
header.SetAckNumber (m_nextRxSequence);
@@ -811,9 +818,12 @@ void TcpSocketImpl::SendRST()
SendEmptyPacket(TcpHeader::RST);
NotifyErrorClose();
CancelAllTimers();
m_endPoint->SetDestroyCallback(MakeNullCallback<void>());
m_tcp->DeAllocate (m_endPoint);
m_endPoint = 0;
if (m_endPoint != 0)
{
m_endPoint->SetDestroyCallback(MakeNullCallback<void>());
m_tcp->DeAllocate (m_endPoint);
m_endPoint = 0;
}
}
@@ -1093,6 +1103,11 @@ bool TcpSocketImpl::SendPendingData (bool withAck)
{
return false; // No data exists
}
if (m_endPoint == 0)
{
NS_LOG_INFO ("TcpSocketImpl::SendPendingData: No endpoint; m_shutdownSend=" << m_shutdownSend);
return false; // Is this the right way to handle this condition?
}
uint32_t nPacketsSent = 0;
while (m_pendingData->SizeFromSeq (m_firstPendingSequence, m_nextTxSequence))
{
@@ -1142,7 +1157,7 @@ bool TcpSocketImpl::SendPendingData (bool withAck)
if (m_shutdownSend)
{
m_errno = ERROR_SHUTDOWN;
return -1;
return false;
}