From 477ac4f17e6a6b377943ecf8e34bc324defc64a6 Mon Sep 17 00:00:00 2001 From: claudio Date: Mon, 30 Sep 2024 12:54:12 +0000 Subject: [PATCH] Improve some currently impossible error path in log_ext_subtype(). Mainly handle unknown ext-communities better and handle the special case of type == -1. OK tb@ --- usr.sbin/bgpd/util.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/usr.sbin/bgpd/util.c b/usr.sbin/bgpd/util.c index 1a99e426f5d..257c7ad59a2 100644 --- a/usr.sbin/bgpd/util.c +++ b/usr.sbin/bgpd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.87 2024/07/03 08:39:43 job Exp $ */ +/* $OpenBSD: util.c,v 1.88 2024/09/30 12:54:12 claudio Exp $ */ /* * Copyright (c) 2006 Claudio Jeker @@ -161,14 +161,16 @@ const struct ext_comm_pairs iana_ext_comms[] = IANA_EXT_COMMUNITIES; const char * log_ext_subtype(int type, uint8_t subtype) { - static char etype[6]; + static char etype[16]; const struct ext_comm_pairs *cp; for (cp = iana_ext_comms; cp->subname != NULL; cp++) { if ((type == cp->type || type == -1) && subtype == cp->subtype) return (cp->subname); } - snprintf(etype, sizeof(etype), "[%u]", subtype); + if (type == -1) + return ("???"); + snprintf(etype, sizeof(etype), "[%hhx:%hhx]", (uint8_t)type, subtype); return (etype); } -- 2.20.1