From 7a16f0a263ec12b8e047dc0c989c2cdea0b243d9 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Wed, 25 Feb 2015 15:41:59 +0200 Subject: [PATCH] monitor: RTNL IFLA flags were printed incorrectly If flags was 0, then an uninitialized buffer was printed. Changed this so that if flags == 0, then just the value is printed. If flags != 0, then print flags values to a buffer that is big enough to hold all the sub-strings. --- monitor/nlmon.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/monitor/nlmon.c b/monitor/nlmon.c index 617f9b02..2820e20e 100644 --- a/monitor/nlmon.c +++ b/monitor/nlmon.c @@ -2621,27 +2621,26 @@ static void ififlags_str(char *str, size_t size, uint16_t flags) { int pos, i; - if (!str || !flags) + pos = sprintf(str, "(0x%02x)", flags); + if (!flags) return; - pos = sprintf(str, "(0x%02x)", flags); pos += sprintf(str + pos, " ["); for (i = 0; rtnl_flags[i].name; i++) { if (flags & rtnl_flags[i].flag) { flags &= ~rtnl_flags[i].flag; - pos += sprintf(str + pos, "%s%c", rtnl_flags[i].name, - flags ? ',' : ']'); + pos += sprintf(str + pos, "%s%s", rtnl_flags[i].name, + flags ? "," : ""); } } - if (flags) - pos += sprintf(str + pos, "0x%x]", flags); + pos += sprintf(str + pos, "]"); } static void print_ifinfomsg(const struct ifinfomsg *info) { - char str[64]; + char str[256]; if (!info) return;