Merge branch 'es/want-color-fd-defensive'
authorJunio C Hamano <gitster@pobox.com>
Fri, 17 Aug 2018 20:09:56 +0000 (13:09 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 17 Aug 2018 20:09:56 +0000 (13:09 -0700)
Futureproofing a helper function that can easily be misused.

* es/want-color-fd-defensive:
color: protect against out-of-bounds reads and writes

color.c
diff --git a/color.c b/color.c
index b1c24c69de652b0b8900e76ebd5b4e6cd24e5203..ebb222ec3323d45bdcd298208903dff9a90d5c3f 100644 (file)
--- a/color.c
+++ b/color.c
@@ -343,6 +343,9 @@ int want_color_fd(int fd, int var)
 
        static int want_auto[3] = { -1, -1, -1 };
 
+       if (fd < 1 || fd >= ARRAY_SIZE(want_auto))
+               BUG("file descriptor out of range: %d", fd);
+
        if (var < 0)
                var = git_use_color_default;