From f1551332be0dd6bc4806b77ab063bf186b341491 Mon Sep 17 00:00:00 2001 From: david Date: Thu, 21 Jan 2010 23:40:10 +0000 Subject: [PATCH] Set the default port state and reason whenever PortList::createPort is called. Formerly the only way to create a port was to call PortList::addPort, which also set the state. Now ports are allocated on demand whenever anything about a port is set. If we don't set the state and reason, they're "unknown" and "unknown-reason". Because of the special handling of PORT_UNKNOWN in the output table, this could lead to an assertion failure reported by Jon Kibler. --- portlist.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/portlist.cc b/portlist.cc index 69f029060..b3a5de0e1 100644 --- a/portlist.cc +++ b/portlist.cc @@ -662,6 +662,7 @@ const Port *PortList::lookupPort(u16 portno, u8 protocol) const { /* Create the port if it doesn't exist; otherwise this is like lookupPort. */ Port *PortList::createPort(u16 portno, u8 protocol) { + Port *p; u16 mapped_portno; u8 mapped_protocol; @@ -670,10 +671,13 @@ Port *PortList::createPort(u16 portno, u8 protocol) { if (!mapPort(&mapped_portno, &mapped_protocol)) return NULL; - if (port_list[mapped_protocol][mapped_portno] == NULL) { - Port *p = new Port(); + p = port_list[mapped_protocol][mapped_portno]; + if (p == NULL) { + p = new Port(); p->portno = portno; p->proto = protocol; + p->state = default_port_state[mapped_protocol].state; + p->reason.reason_id = ER_NORESPONSE; port_list[mapped_protocol][mapped_portno] = p; }