]> The Tcpdump Group git mirrors - tcpdump/commitdiff
BGP: Address a -Wformat-truncation= compiler warning
authorFrancois-Xavier Le Bail <[email protected]>
Fri, 14 Aug 2020 15:22:15 +0000 (17:22 +0200)
committerFrancois-Xavier Le Bail <[email protected]>
Fri, 14 Aug 2020 15:23:55 +0000 (17:23 +0200)
The warning was:
./print-bgp.c: In function 'bgp_vpn_rd_print':
./print-bgp.c:797:65: warning: '%u' directive output may be truncated
writing between 1 and 3 bytes into a region of size between 2 and 31
[-Wformat-truncation=]
  797 |         snprintf(pos, sizeof(rd) - (pos - rd), "%s:%u (%u.%u.%u.%u:%u)",
      |                                                                 ^~
./print-bgp.c:797:48: note: directive argument in the range [0, 255]
  797 |         snprintf(pos, sizeof(rd) - (pos - rd), "%s:%u (%u.%u.%u.%u:%u)",
      |                                                ^~~~~~~~~~~~~~~~~~~~~~~~
./print-bgp.c:797:48: note: directive argument in the range [0, 65535]
./print-bgp.c:797:9: note: 'snprintf' output between 15 and 50 bytes
into a destination of size 41
  797 |         snprintf(pos, sizeof(rd) - (pos - rd), "%s:%u (%u.%u.%u.%u:%u)",
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  798 |                     as_printf(ndo, astostr, sizeof(astostr), GET_BE_U_4(pptr + 2)),
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  799 |                     GET_BE_U_2(pptr + 6), GET_U_1(pptr + 2),
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  800 |                     GET_U_1(pptr + 3), GET_U_1(pptr + 4),
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  801 |                     GET_U_1(pptr + 5), GET_BE_U_2(pptr + 6));
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

print-bgp.c

index e5512ed89c1d1ac625072f39014cb701807b4364..67643be5d82077dbdfdb254819c554e58bb8a9b1 100644 (file)
@@ -557,7 +557,8 @@ static const struct tok bgp_add_path_recvsend[] = {
     { 0, NULL },
 };
 
-static char astostr[20];
+/* allocate space for the largest possible string */
+static char astostr[sizeof("xxxxx.xxxxx")];
 
 /*
  * as_printf
@@ -769,7 +770,7 @@ bgp_vpn_rd_print(netdissect_options *ndo,
                  const u_char *pptr)
 {
     /* allocate space for the largest possible string */
-    static char rd[sizeof("xxxxxxxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
+    static char rd[sizeof("xxxxx.xxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
     char *pos = rd;
 
     /* ok lets load the RD format */