scout: band-aid -Wformat-truncation 70/13470/2
authorBenjamin Kaduk <kaduk@mit.edu>
Sat, 2 Feb 2019 23:02:08 +0000 (17:02 -0600)
committerBenjamin Kaduk <kaduk@mit.edu>
Fri, 1 Mar 2019 14:48:30 +0000 (09:48 -0500)
gcc8 gets pretty confused about the bounds on these things (presumably
due to our alignment options) and thinks this could potentially be a huge
string.  Check for truncation to appease the compiler, instead of trying
to ensure that the buffer is big enough.

Change-Id: I4c1e0e6a5a38ee67845cbb7791b280b965989bc8
Reviewed-on: https://gerrit.openafs.org/13470
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Tested-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

src/scout/scout.c

index 294c81e..064f625 100644 (file)
@@ -1791,14 +1791,18 @@ execute_scout(int a_numservers, struct cmd_item *a_srvname, int a_pkg)
            snprintf(attn_label, sizeof(attn_label), "%s: < %d blocks free",
                     scout_label[5], scout_attn_disk_minfree);
        }
-       snprintf(scout_Banner, sizeof(scout_Banner),
-                "%*s %*s %*s %*s %*s %s",
-                scout_col_width[0], scout_label[0],
-                scout_col_width[1], scout_label[1],
-                scout_col_width[2], scout_label[2],
-                scout_col_width[3], scout_label[3],
-                scout_col_width[4], scout_label[4],
-                attn_label);
+       code = snprintf(scout_Banner, sizeof(scout_Banner),
+                       "%*s %*s %*s %*s %*s %s",
+                       scout_col_width[0], scout_label[0],
+                       scout_col_width[1], scout_label[1],
+                       scout_col_width[2], scout_label[2],
+                       scout_col_width[3], scout_label[3],
+                       scout_col_width[4], scout_label[4],
+                       attn_label);
+       if (code < 0 || code >= sizeof(scout_Banner)) {
+           fprintf(stderr, "[%s] Truncation while generating banner\n", rn);
+           return -1;
+       }
 
        lightdata = (struct gator_lightobj *)(scout_banner1_lp->o_data);
        mini_justify(scout_Banner, lightdata->label, scout_frameDims.maxx,