From 3a028edbc83f160e60266aa3c75b0685ad4b85db Mon Sep 17 00:00:00 2001 From: Geoff Salmon Date: Mon, 11 Mar 2013 17:29:18 -0400 Subject: [PATCH] pmc: avoid printing invalid data from empty TLVs Also adds additional null-check to bin2str to avoid crashing on empty messages. Signed-off-by: Geoff Salmon --- pmc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pmc.c b/pmc.c index 8f16463..ad239e0 100644 --- a/pmc.c +++ b/pmc.c @@ -130,6 +130,8 @@ static char *bin2str_impl(Octet *data, int len, char *buf, int buf_len) { if (len > MAX_PRINT_BYTES) len = MAX_PRINT_BYTES; buf[0] = '\0'; + if (!data) + return buf; if (len) offset += snprintf(buf, buf_len, "%02hhx", data[0]); for (i = 1; i < len; i++) { @@ -206,6 +208,10 @@ static void pmc_show(struct ptp_message *msg, FILE *fp) fprintf(fp, "unknown-tlv "); } mgt = (struct management_tlv *) msg->management.suffix; + if (mgt->length == 2 && mgt->id != NULL_MANAGEMENT) { + fprintf(fp, "empty-tlv "); + goto out; + } switch (mgt->id) { case CLOCK_DESCRIPTION: cd = &msg->last_tlv.cd;