threads / patch / 18934

patchinit: Do not segfault on big GIT_TEMPLATE_DIR environment variable

Subject: [PATCH] init: Do not segfault on big GIT_TEMPLATE_DIR environment variable

## tl;dr

One message between Apr 18, 2009 and Apr 18, 2009. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Frank Lichtenheld· Apr 18, 2009, 14:14 UTC · lore
From: Frank Lichtenheld <flichtenheld@astaro.com>
Signed-off-by: Frank Lichtenheld <flichtenheld@astaro.com>
---
 builtin-init-db.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
Show changes to builtin-init-db.c +3 −1
diff --git a/builtin-init-db.c b/builtin-init-db.c
index 4e02b33..d1fa12a 100644
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
@@ -122,8 +122,10 @@ static void copy_templates(const char *template_dir)
 		template_dir = system_path(DEFAULT_GIT_TEMPLATE_DIR);
 	if (!template_dir[0])
 		return;
+	template_len = strlen(template_dir);
+	if (PATH_MAX <= (template_len+strlen("/config")))
+		die("insanely long template path %s", template_dir);
 	strcpy(template_path, template_dir);
-	template_len = strlen(template_path);
 	if (template_path[template_len-1] != '/') {
 		template_path[template_len++] = '/';
 		template_path[template_len] = 0;
-- 
1.6.2.1

← back to recent threads