Signed-off-by: Daniel Gröber <dxld@xxxxxxxxxxxxx> --- src/conntrack/snprintf_default.c | 12 ++++-------- src/conntrack/snprintf_xml.c | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/conntrack/snprintf_default.c b/src/conntrack/snprintf_default.c index d00c5cb..8e3d41c 100644 --- a/src/conntrack/snprintf_default.c +++ b/src/conntrack/snprintf_default.c @@ -13,20 +13,16 @@ static int __snprintf_l3protocol(char *buf, unsigned int len, const struct nf_conntrack *ct) { - return (snprintf(buf, len, "%-8s %u ", - l3proto2str[ct->head.orig.l3protonum] == NULL ? - "unknown" : l3proto2str[ct->head.orig.l3protonum], - ct->head.orig.l3protonum)); + uint8_t num = ct->head.orig.l3protonum; + return snprintf(buf, len, "%-8s %u ", __l3proto2str(num), num); } int __snprintf_protocol(char *buf, unsigned int len, const struct nf_conntrack *ct) { - return (snprintf(buf, len, "%-8s %u ", - proto2str[ct->head.orig.protonum] == NULL ? - "unknown" : proto2str[ct->head.orig.protonum], - ct->head.orig.protonum)); + uint8_t num = ct->head.orig.protonum; + return snprintf(buf, len, "%-8s %u ", __proto2str(num), num); } static int __snprintf_timeout(char *buf, diff --git a/src/conntrack/snprintf_xml.c b/src/conntrack/snprintf_xml.c index c3a836a..6a9dfb4 100644 --- a/src/conntrack/snprintf_xml.c +++ b/src/conntrack/snprintf_xml.c @@ -55,12 +55,28 @@ const char *__proto2str(uint8_t protonum) { - return proto2str[protonum] ? proto2str[protonum] : "unknown"; + const char *str = NULL; + + if(protonum < asizeof(proto2str)) + str = proto2str[protonum]; + + if(str == NULL) + str = "unknown"; + + return str; } const char *__l3proto2str(uint8_t protonum) { - return l3proto2str[protonum] ? l3proto2str[protonum] : "unknown"; + const char *str = NULL; + + if(protonum < asizeof(l3proto2str)) + str = l3proto2str[protonum]; + + if(str == NULL) + str = "unknown"; + + return str; } static int __snprintf_ipv4_xml(char *buf, -- 2.20.1