blame: prefer xsnprintf to strcpy for colors
Our color buffers are all COLOR_MAXLEN, which fits the largest possible color. So we can never overflow the buffer by copying an existing color. However, using strcpy() makes it harder to audit the code-base for calls that _are_ problems. We should use something like xsnprintf(), which shows the reader that we expect this never to fail (and provides a run-time assertion if it does, just in case). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jul 13, 2018 at 16:43 UTC
022d2ac1f3f89f5af1e712f72bfc69c716d64926
1 file changed
+3
-1
builtin/blame.c
+3
-1
@@ -1060,7 +1060,9 @@ parse_done:
1060
find_alignment(&sb, &output_option);
1061
if (!*repeated_meta_color &&
1062
(output_option & OUTPUT_COLOR_LINE))
1063
- strcpy(repeated_meta_color, GIT_COLOR_CYAN);
1063
+ xsnprintf(repeated_meta_color,
1064
+ sizeof(repeated_meta_color),
1065
+ "%s", GIT_COLOR_CYAN);
1066
}
1067
if (output_option & OUTPUT_ANNOTATE_COMPAT)
1068
output_option &= ~(OUTPUT_COLOR_LINE | OUTPUT_SHOW_AGE_WITH_COLOR);