Discussion:
[Linuxptp-devel] [PATCH] pmc: avoid printing invalid data from empty TLVs
Geoff Salmon
2013-03-11 21:29:18 UTC
Permalink
Also adds additional null-check to bin2str to avoid crashing on empty
messages.

Signed-off-by: Geoff Salmon <***@se-instruments.com>
---
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;
--
1.7.9.5
Richard Cochran
2013-03-12 19:31:25 UTC
Permalink
Post by Geoff Salmon
Also adds additional null-check to bin2str to avoid crashing on empty
messages.
---
pmc.c | 6 ++++++
1 file changed, 6 insertions(+)
Applied.

Thanks,
Richard

Loading...