git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix buffer overflow in git-grep
@ 2008-07-16 10:15 Dmitry Potapov
  2008-07-16 10:35 ` Johannes Schindelin
  0 siblings, 1 reply; 10+ messages in thread
From: Dmitry Potapov @ 2008-07-16 10:15 UTC (permalink / raw)
  To: git; +Cc: Dmitry Potapov

If PATH_MAX on your system is smaller than any path stored in the git
repository, that can cause memory corruption inside of the grep_tree
function used by git-grep.

Signed-off-by: Dmitry Potapov <dpotapov@gmail.com>
---
 builtin-grep.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/builtin-grep.c b/builtin-grep.c
index ef29910..530a53d 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -441,14 +441,17 @@ static int grep_tree(struct grep_opt *opt, const char **paths,
 	len = strlen(path_buf);
 
 	while (tree_entry(tree, &entry)) {
-		strcpy(path_buf + len, entry.path);
+		int te_len = tree_entry_len(entry.path, entry.sha1);
+		if (len + te_len >= PATH_MAX + tn_len)
+			die ("path too long: %s", path_buf+tn_len);
+		memcpy(path_buf + len, entry.path, te_len);
 
 		if (S_ISDIR(entry.mode))
 			/* Match "abc/" against pathspec to
 			 * decide if we want to descend into "abc"
 			 * directory.
 			 */
-			strcpy(path_buf + len + tree_entry_len(entry.path, entry.sha1), "/");
+			strcpy(path_buf + len + te_len, "/");
 
 		if (!pathspec_matches(paths, down))
 			;
-- 
1.5.6.3.1.gb5587a

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

end of thread, other threads:[~2008-07-16 15:41 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-16 10:15 [PATCH] Fix buffer overflow in git-grep Dmitry Potapov
2008-07-16 10:35 ` Johannes Schindelin
2008-07-16 11:54   ` Dmitry Potapov
2008-07-16 14:33     ` Dmitry Potapov
2008-07-16 14:47       ` Johannes Schindelin
2008-07-16 14:54       ` [PATCH] Fix buffer overflow in git diff Dmitry Potapov
2008-07-16 14:54         ` [PATCH] Fix buffer overflow in prepare_attr_stack Dmitry Potapov
2008-07-16 15:21           ` Johannes Sixt
2008-07-16 15:39             ` [PATCH v2] " Dmitry Potapov
2008-07-16 15:33   ` [PATCH v2] Fix buffer overflow in git-grep Dmitry Potapov

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 NNTP newsgroup(s).