init: Do not segfault on big GIT_TEMPLATE_DIR environment variable
Signed-off-by: Frank Lichtenheld <flichtenheld@astaro.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Frank Lichtenheld committed
Apr 18, 2009 at 16:14 UTC
32d1776b1341c17b99da862e80ddf151a5b558fe
2 files changed
+12
-1
builtin-init-db.c
+3
-1
@@ -122,8 +122,10 @@ static void copy_templates(const char *template_dir)
122
template_dir = system_path(DEFAULT_GIT_TEMPLATE_DIR);
123
if (!template_dir[0])
124
return;
125
+ template_len = strlen(template_dir);
126
+ if (PATH_MAX <= (template_len+strlen("/config")))
127
+ die("insanely long template path %s", template_dir);
128
strcpy(template_path, template_dir);
126
- template_len = strlen(template_path);
129
if (template_path[template_len-1] != '/') {
130
template_path[template_len++] = '/';
131
template_path[template_len] = 0;
t/t0001-init.sh
+9
@@ -199,4 +199,13 @@ test_expect_success 'init honors global core.sharedRepository' '
199
x`git config -f shared-honor-global/.git/config core.sharedRepository`
200
'
201
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
+
211
test_done