From 32d1776b1341c17b99da862e80ddf151a5b558fe Mon Sep 17 00:00:00 2001 From: Frank Lichtenheld Date: Sat, 18 Apr 2009 16:14:02 +0200 Subject: [PATCH] init: Do not segfault on big GIT_TEMPLATE_DIR environment variable Signed-off-by: Frank Lichtenheld Signed-off-by: Junio C Hamano --- builtin-init-db.c | 4 +++- t/t0001-init.sh | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/builtin-init-db.c b/builtin-init-db.c index d30c3fe2ca..6cc945d507 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; diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 5ac0a273a9..e3d846420d 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -199,4 +199,13 @@ test_expect_success 'init honors global core.sharedRepository' ' x`git config -f shared-honor-global/.git/config core.sharedRepository` ' +test_expect_success 'init rejects insanely long --template' ' + ( + insane=$(printf "x%09999dx" 1) && + mkdir test && + cd test && + test_must_fail git init --template=$insane + ) +' + test_done -- 2.11.4.GIT