4693f0
commit 43b2f5d1207a010f1df67e101b129b09502371e2
4693f0
Author: Hangbin Liu <liuhangbin@gmail.com>
4693f0
Date:   Fri May 12 15:36:45 2017 +0800
4693f0
4693f0
    msg: use last_tlv if there is not enough room for another tlv
4693f0
    
4693f0
    If the len is not enought for another tlv process. e.g. one more bytes
4693f0
    padding at the end of message. And we set extra to NULL instead of
4693f0
    msg->last_tlv in tlv_post_recv(). Then the msg->last_tlv will not be
4693f0
    initialised. And program will crash if we read msg->last_tlv. e.g. in
4693f0
    function pmc_show().
4693f0
    
4693f0
    Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
4693f0
4693f0
diff --git a/msg.c b/msg.c
4693f0
index a38b815..4b3d926 100644
4693f0
--- a/msg.c
4693f0
+++ b/msg.c
4693f0
@@ -140,7 +140,7 @@ static int suffix_post_recv(uint8_t *ptr, int len, struct tlv_extra *last)
4693f0
 		}
4693f0
 		len -= tlv->length;
4693f0
 		ptr += tlv->length;
4693f0
-		err = tlv_post_recv(tlv, len ? NULL : last);
4693f0
+		err = tlv_post_recv(tlv, len > sizeof(struct TLV) ? NULL : last);
4693f0
 		if (err)
4693f0
 			return err;
4693f0
 	}
4693f0
commit 95b5a13cb2787b6a436ad395bb4931d1661e59a7
4693f0
Author: Hangbin Liu <liuhangbin@gmail.com>
4693f0
Date:   Tue May 23 14:49:55 2017 +0800
4693f0
4693f0
    pmc: goto out when get unknown management tlv
4693f0
    
4693f0
    If handle unknown management tlv. The management message id and format are
4693f0
    also unknown, thus we may crash due to access unknown area.
4693f0
    
4693f0
    Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
4693f0
4693f0
diff --git a/pmc.c b/pmc.c
4693f0
index cefa771..af9cc63 100644
4693f0
--- a/pmc.c
4693f0
+++ b/pmc.c
4693f0
@@ -217,6 +217,7 @@ static void pmc_show(struct ptp_message *msg, FILE *fp)
4693f0
 		goto out;
4693f0
 	} else {
4693f0
 		fprintf(fp, "unknown-tlv ");
4693f0
+		goto out;
4693f0
 	}
4693f0
 	mgt = (struct management_tlv *) msg->management.suffix;
4693f0
 	if (mgt->length == 2 && mgt->id != TLV_NULL_MANAGEMENT) {