From 14da55719c9e9bff1f8e7e02c8a8d47c59fb7b4a Mon Sep 17 00:00:00 2001 From: Pat Riehecky Date: Wed, 6 Jun 2018 11:10:25 -0500 Subject: [PATCH] mcas: Make sure 'padding' is null-terminated 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 Reviewed-by: Benjamin Kaduk --- src/mcas/set_harness.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mcas/set_harness.c b/src/mcas/set_harness.c index 9a0d80b..3cd5d40 100644 --- a/src/mcas/set_harness.c +++ b/src/mcas/set_harness.c @@ -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'; } -- 1.9.4