From: Jeff King Date: Fri, 13 Jul 2018 20:43:50 +0000 (-0400) Subject: blame: prefer xsnprintf to strcpy for colors X-Git-Tag: v2.19.0-rc0~119^2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/022d2ac1f3f89f5af1e712f72bfc69c716d64926 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 Signed-off-by: Junio C Hamano --- diff --git a/builtin/blame.c b/builtin/blame.c index dc7870a561..758cd39dd1 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -1060,7 +1060,9 @@ int cmd_blame(int argc, const char **argv, const char *prefix) find_alignment(&sb, &output_option); if (!*repeated_meta_color && (output_option & OUTPUT_COLOR_LINE)) - strcpy(repeated_meta_color, GIT_COLOR_CYAN); + xsnprintf(repeated_meta_color, + sizeof(repeated_meta_color), + "%s", GIT_COLOR_CYAN); } if (output_option & OUTPUT_ANNOTATE_COMPAT) output_option &= ~(OUTPUT_COLOR_LINE | OUTPUT_SHOW_AGE_WITH_COLOR);