Skip to content

Commit 65bb21e

Browse files
sunshinecogitster
authored andcommitted
color: protect against out-of-bounds reads and writes
want_color_fd() is designed to work only with standard output and error file descriptors and stores information about each descriptor in an array. However, it doesn't verify that the passed-in descriptor lives within that set, which, with a buggy caller, could lead to access or assignment outside the array bounds. Signed-off-by: Eric Sunshine <[email protected]> Acked-by: Johannes Schindelin <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 53f9a3e commit 65bb21e

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

color.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,9 @@ int want_color_fd(int fd, int var)
343343

344344
static int want_auto[3] = { -1, -1, -1 };
345345

346+
if (fd < 1 || fd >= ARRAY_SIZE(want_auto))
347+
BUG("file descriptor out of range: %d", fd);
348+
346349
if (var < 0)
347350
var = git_use_color_default;
348351

0 commit comments

Comments
 (0)