Skip to content

Commit 3ac6437

Browse files
dschogitster
authored andcommitted
Fix is_gitfile() for files too small or larger than PATH_MAX to be a gitfile
The logic to check whether a file is a gitfile used the heuristics that a gitfile cannot be larger than PATH_MAX or smaller than 10 bytes (as its contents is "gitdir: " followed by a path) and returned early. But it returned with a wrong value. It should have said "this cannot possibly be a gitfile" by returning 0, but it returned 1 instead. Our test cases do not cover this, as the bundle files produced are smaller than PATH_MAX, except on Windows. While at it, fix the faulty logic that the path stored in a gitfile cannot be larger than PATH_MAX-sizeof("gitdir: "). Problem identified by running the test suite in msysGit, offending commit identified by Jörg Rosenkranz. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 0c80fdb commit 3ac6437

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

transport.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,8 +875,8 @@ static int is_gitfile(const char *url)
875875
return 0;
876876
if (!S_ISREG(st.st_mode))
877877
return 0;
878-
if (st.st_size < 10 || st.st_size > PATH_MAX)
879-
return 1;
878+
if (st.st_size < 10 || st.st_size > 9 + PATH_MAX)
879+
return 0;
880880

881881
fd = open(url, O_RDONLY);
882882
if (fd < 0)

0 commit comments

Comments
 (0)