Skip to content

Commit 32d1776

Browse files
flichtenheldgitster
authored andcommitted
init: Do not segfault on big GIT_TEMPLATE_DIR environment variable
Signed-off-by: Frank Lichtenheld <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e0b3cc0 commit 32d1776

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

builtin-init-db.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@ static void copy_templates(const char *template_dir)
122122
template_dir = system_path(DEFAULT_GIT_TEMPLATE_DIR);
123123
if (!template_dir[0])
124124
return;
125+
template_len = strlen(template_dir);
126+
if (PATH_MAX <= (template_len+strlen("/config")))
127+
die("insanely long template path %s", template_dir);
125128
strcpy(template_path, template_dir);
126-
template_len = strlen(template_path);
127129
if (template_path[template_len-1] != '/') {
128130
template_path[template_len++] = '/';
129131
template_path[template_len] = 0;

t/t0001-init.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,13 @@ test_expect_success 'init honors global core.sharedRepository' '
199199
x`git config -f shared-honor-global/.git/config core.sharedRepository`
200200
'
201201

202+
test_expect_success 'init rejects insanely long --template' '
203+
(
204+
insane=$(printf "x%09999dx" 1) &&
205+
mkdir test &&
206+
cd test &&
207+
test_must_fail git init --template=$insane
208+
)
209+
'
210+
202211
test_done

0 commit comments

Comments
 (0)