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 <gsalmon@se-instruments.com>
master
Geoff Salmon 2013-03-11 17:29:18 -04:00 committed by Richard Cochran
parent 1ff9d0d0d2
commit 3a028edbc8
1 changed files with 6 additions and 0 deletions

6
pmc.c
View File

@ -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;