Skip to content

Commit 022d2ac

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 297bdf0 commit 022d2ac

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

builtin/blame.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,9 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
10601060
find_alignment(&sb, &output_option);
10611061
if (!*repeated_meta_color &&
10621062
(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);
10641066
}
10651067
if (output_option & OUTPUT_ANNOTATE_COMPAT)
10661068
output_option &= ~(OUTPUT_COLOR_LINE | OUTPUT_SHOW_AGE_WITH_COLOR);

0 commit comments

Comments
 (0)