From 7d3e440c6a78446ae6a5d8366970c5405030824d Mon Sep 17 00:00:00 2001 From: "Windriver Yong-heon.Kim" Date: Tue, 21 Jun 2016 19:44:44 +0900 Subject: [PATCH 1/2] Fix memory leak that occurs when receive unexpected message in PTP packet. Signed-off-by: Windriver Yong-heon.Kim --- daemons/gptp/common/ptp_message.cpp | 31 +++++++++++++++++------------ 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/daemons/gptp/common/ptp_message.cpp b/daemons/gptp/common/ptp_message.cpp index a2101731e0..b535c3f1bd 100644 --- a/daemons/gptp/common/ptp_message.cpp +++ b/daemons/gptp/common/ptp_message.cpp @@ -98,11 +98,6 @@ PTPMessageCommon *buildPTPMessage messageType = (MessageType) (tspec_msg_t & 0xF); transportSpecific = (tspec_msg_t >> 4) & 0x0F; - if (1 != transportSpecific) { - GPTP_LOG_EXCEPTION("*** Received message with unsupported transportSpecific type=%d", transportSpecific); - goto done; - } - sourcePortIdentity = new PortIdentity ((uint8_t *) (buf + PTP_COMMON_HDR_SOURCE_CLOCK_ID @@ -145,7 +140,7 @@ PTPMessageCommon *buildPTPMessage ("*** Received an event packet but cannot retrieve timestamp, discarding. messageType=%u,error=%d\n%s", messageType, ts_good, msg); //_exit(-1); - return NULL; + goto abort; } else { @@ -153,6 +148,11 @@ PTPMessageCommon *buildPTPMessage } } + + if (1 != transportSpecific) { + GPTP_LOG_EXCEPTION("*** Received message with unsupported transportSpecific type=%d", transportSpecific); + goto abort; + } switch (messageType) { case SYNC_MESSAGE: @@ -162,7 +162,7 @@ PTPMessageCommon *buildPTPMessage // Be sure buffer is the correction size if (size < PTP_COMMON_HDR_LENGTH + PTP_SYNC_LENGTH) { - goto done; + goto abort; } { PTPMessageSync *sync_msg = new PTPMessageSync(); @@ -186,7 +186,7 @@ PTPMessageCommon *buildPTPMessage // Be sure buffer is the correction size if (size < (int)(PTP_COMMON_HDR_LENGTH + PTP_FOLLOWUP_LENGTH + sizeof(FollowUpTLV))) { - goto done; + goto abort; } { PTPMessageFollowUp *followup_msg = @@ -237,7 +237,7 @@ PTPMessageCommon *buildPTPMessage // Be sure buffer is the correction size if (size < PTP_COMMON_HDR_LENGTH + PTP_PDELAY_REQ_LENGTH && /* For Broadcom compatibility */ size != 46) { - goto done; + goto abort; } { PTPMessagePathDelayReq *pdelay_req_msg = @@ -285,7 +285,7 @@ PTPMessageCommon *buildPTPMessage // Be sure buffer is the correction size if (size < PTP_COMMON_HDR_LENGTH + PTP_PDELAY_RESP_LENGTH) { - goto done; + goto abort; } { PTPMessagePathDelayResp *pdelay_resp_msg = @@ -344,7 +344,7 @@ PTPMessageCommon *buildPTPMessage // Be sure buffer is the correction size // if( size < PTP_COMMON_HDR_LENGTH + PTP_PDELAY_FOLLOWUP_LENGTH ) { -// goto done; +// goto abort; // } { PTPMessagePathDelayRespFollowUp *pdelay_resp_fwup_msg = @@ -487,7 +487,7 @@ PTPMessageCommon *buildPTPMessage (int)messageType); port->incCounter_ieee8021AsPortStatRxPTPPacketDiscard(); - goto done; + goto abort; } msg->_gc = false; @@ -523,10 +523,15 @@ PTPMessageCommon *buildPTPMessage msg->_timestamp = timestamp; msg->_timestamp_counter_value = counter_value; - done: delete timer; return msg; + +abort: + delete sourcePortIdentity; + delete timer; + + return NULL; } void PTPMessageCommon::processMessage(IEEE1588Port * port) From dc06c0a2e7f41d13ef2b86384826954c77c81389 Mon Sep 17 00:00:00 2001 From: "Windriver Yong-heon.Kim" Date: Tue, 21 Jun 2016 19:50:19 +0900 Subject: [PATCH 2/2] Fix to remove the duplecated assignment InterfaceName object. Signed-off-by: Windriver Yong-heon.Kim --- daemons/gptp/linux/src/daemon_cl.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/daemons/gptp/linux/src/daemon_cl.cpp b/daemons/gptp/linux/src/daemon_cl.cpp index 22970e1833..d6e52e6737 100644 --- a/daemons/gptp/linux/src/daemon_cl.cpp +++ b/daemons/gptp/linux/src/daemon_cl.cpp @@ -320,10 +320,6 @@ int main(int argc, char **argv) restoredataptr = (char *)restoredata; } - if (argc < 2) - return -1; - ifname = new InterfaceName(argv[1], strlen(argv[1])); - #ifdef ARCH_INTELCE HWTimestamper *timestamper = new LinuxTimestamperIntelCE(); #else