Improve some currently impossible error path in log_ext_subtype().
authorclaudio <claudio@openbsd.org>
Mon, 30 Sep 2024 12:54:12 +0000 (12:54 +0000)
committerclaudio <claudio@openbsd.org>
Mon, 30 Sep 2024 12:54:12 +0000 (12:54 +0000)
Mainly handle unknown ext-communities better and handle the special
case of type == -1.
OK tb@

usr.sbin/bgpd/util.c

index 1a99e42..257c7ad 100644 (file)
@@ -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 <claudio@openbsd.org>
@@ -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);
 }