mcas: Make sure 'padding' is null-terminated 64/13164/4
authorPat Riehecky <riehecky@fnal.gov>
Wed, 6 Jun 2018 16:10:25 +0000 (11:10 -0500)
committerBenjamin Kaduk <kaduk@mit.edu>
Thu, 14 Jun 2018 23:55:18 +0000 (19:55 -0400)
With 'padding' explicitly filled with all spaces string copy operations
may result in unexpected values.  Padding is extended by 1 and null
terminated to avoid unexpected behavior.
(via cppcheck)

Change-Id: I8a9845ae87002018705ad23c2b089c8ef571b7bc
Reviewed-on: https://gerrit.openafs.org/13164
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

src/mcas/set_harness.c

index 9a0d80b..3cd5d40 100644 (file)
@@ -116,8 +116,9 @@ static void dump_log (void) {
              "---------------------------\n");
     for (i = 0; i < num_log_records; i ++)
     {
-        char padding[40];
-        strcpy(padding, "                                        ");
+        char padding[41];
+        memset(padding, ' ', sizeof(padding) - 1);
+        padding[40] = '\0';
         if (30-strlen(log_records[i].name) >= 0){
             padding[30-strlen(log_records[i].name)] = '\0';
         }