git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] color: protect against out-of-bounds array access/assignment
@ 2018-08-02  9:32 Eric Sunshine
  2018-08-02 12:38 ` Johannes Schindelin
  2018-08-03  6:07 ` Jonathan Nieder
  0 siblings, 2 replies; 8+ messages in thread
From: Eric Sunshine @ 2018-08-02  9:32 UTC (permalink / raw)
  To: git; +Cc: Johannes Schindelin, Eric Sunshine

want_color_fd() is designed to work only with standard input, 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/assignment outside the array bounds.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
---

Just something I noticed while studying this code in relation to a patch
review.

 color.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/color.c b/color.c
index b1c24c69de..b0be9ce505 100644
--- 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 < 0 || fd >= ARRAY_SIZE(want_auto))
+	    BUG("file descriptor out of range: %d", fd);
+
 	if (var < 0)
 		var = git_use_color_default;
 
-- 
2.18.0.599.g4ce2a8faa4.dirty


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-08-03  6:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-02  9:32 [PATCH] color: protect against out-of-bounds array access/assignment Eric Sunshine
2018-08-02 12:38 ` Johannes Schindelin
2018-08-02 17:36   ` Junio C Hamano
2018-08-02 17:45     ` Eric Sunshine
2018-08-02 19:24       ` Junio C Hamano
2018-08-02 19:30         ` Jeff King
2018-08-03  6:07 ` Jonathan Nieder
2018-08-03  6:43   ` Eric Sunshine

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).