From: Claudio Jeker Subject: bgpd: improve log_ext_subtype() To: tech@openbsd.org Date: Mon, 30 Sep 2024 11:40:25 +0200 log_ext_subtype() is not printing the full information at the moment. Also modern gcc warns about a possible snprintf() overflow (which as usual is humbug but gcc is just not smart enough). Anyway lets make this better. log_ext_subtype() can be called with type == -1 (but I think this actually never happens). In that case only the subtype needs to match (which again should always happen for the -1 case). So if type is -1 and the for loop did not match just return "???" since we have no clue what subtype this is. log_ext_subtype() can also be called with a completely unknown ext-community (which we get from the wire). In that case type is actually a uint8_t and we want to return both type and subtype value. So do that even though this again should not happen (since the only place that is possible is in bgpctl and there we just print the 64bit value). So in the end, nothing of this is really needed but I think it is good to make log_ext_subtype() cope with all inputs. -- :wq Claudio Index: util.c =================================================================== RCS file: /cvs/src/usr.sbin/bgpd/util.c,v diff -u -p -r1.87 util.c --- util.c 3 Jul 2024 08:39:43 -0000 1.87 +++ util.c 29 Sep 2024 09:10:04 -0000 @@ -161,14 +161,16 @@ const struct ext_comm_pairs iana_ext_com 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); }