init: use strbufs to store paths
commit9c28390bda4bb86f48a3145417c1cb1892782c47
authorJeff King <peff@peff.net>
Mon, 5 Oct 2015 03:46:04 +0000 (4 23:46 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 5 Oct 2015 18:07:04 +0000 (5 11:07 -0700)
tree61720ec3de74f3a84a8885f5585e91948b4d68cd
parentfdf729661a777d8bd598f40055d92b2df5601332
init: use strbufs to store paths

The init code predates strbufs, and uses PATH_MAX-sized
buffers along with many manual checks on intermediate sizes
(some of which make magic assumptions, such as that init
will not create a path inside .git longer than 50
characters).

We can simplify this greatly by using strbufs, which drops
some hard-to-verify strcpy calls in favor of git_path_buf.
While we're in the area, let's also convert existing calls
to git_path to the safer git_path_buf (our existing calls
were passed to pretty tame functions, and so were not a
problem, but it's easy to be consistent and safe here).

Note that we had an explicit test that "git init" rejects
long template directories. This comes from 32d1776 (init: Do
not segfault on big GIT_TEMPLATE_DIR environment variable,
2009-04-18). We can drop the test_must_fail here, as we now
accept this and need only confirm that we don't segfault,
which was the original point of the test.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/init-db.c
t/t0001-init.sh