Git development
 help / color / mirror / Atom feed
* [PATCH] Fix is_gitfile() for files larger than PATH_MAX
@ 2011-10-11 19:25 Johannes Schindelin
  2011-10-11 20:25 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Johannes Schindelin @ 2011-10-11 19:25 UTC (permalink / raw)
  To: git, gitster

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1276 bytes --]


The logic to check whether a file is a gitfile used the heuristics that
the file cannot be larger than PATH_MAX. But in that case it returned the
wrong value. 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("gitfile: ").

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>
---
	This patch should apply cleanly to 'next', which we track in
	msysgit/git.

	The task of adding a test case is something I leave to someone who
	wants to get involved with Git development and needs an easy way
	in.

 transport.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/transport.c b/transport.c
index f3195c0..57138d9 100644
--- a/transport.c
+++ b/transport.c
@@ -868,8 +868,8 @@ static int is_gitfile(const char *url)
 		return 0;
 	if (!S_ISREG(st.st_mode))
 		return 0;
-	if (st.st_size < 10 || st.st_size > PATH_MAX)
-		return 1;
+	if (st.st_size < 10 || st.st_size > 9 + PATH_MAX)
+		return 0;
 
 	fd = open(url, O_RDONLY);
 	if (fd < 0)
-- 
1.7.6.msysgit.0.584.g2cbf

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix is_gitfile() for files larger than PATH_MAX
  2011-10-11 19:25 [PATCH] Fix is_gitfile() for files larger than PATH_MAX Johannes Schindelin
@ 2011-10-11 20:25 ` Junio C Hamano
  2011-10-11 20:58   ` Phil Hord
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2011-10-11 20:25 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: git

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> The logic to check whether a file is a gitfile used the heuristics that
> the file cannot be larger than PATH_MAX. But in that case it returned the
> wrong value. 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("gitfile: ").
>
> 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>
> ---
> 	This patch should apply cleanly to 'next', which we track in
> 	msysgit/git.
>
> 	The task of adding a test case is something I leave to someone who
> 	wants to get involved with Git development and needs an easy way
> 	in.
>
>  transport.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/transport.c b/transport.c
> index f3195c0..57138d9 100644
> --- a/transport.c
> +++ b/transport.c
> @@ -868,8 +868,8 @@ static int is_gitfile(const char *url)
>  		return 0;
>  	if (!S_ISREG(st.st_mode))
>  		return 0;
> -	if (st.st_size < 10 || st.st_size > PATH_MAX)
> -		return 1;
> +	if (st.st_size < 10 || st.st_size > 9 + PATH_MAX)
> +		return 0;

We are asked if the file is likely to be a single-liner "gitfile: <path>",
and were answering yes when it is a very short file (less than 10 bytes)
that cannot possibly even contain "gitfile: " prefix.

I suspect that we can and should get rid of the "cannot be very long"
check altogether---we do open and check the file, and after all it is not
like we are throwing different strings as "url" argument to this function
at random and this function needs heuristics to reject bogus input
early. The argument is an input from the user.

Quite an embarrasing bug. Thanks for spotting.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix is_gitfile() for files larger than PATH_MAX
  2011-10-11 20:25 ` Junio C Hamano
@ 2011-10-11 20:58   ` Phil Hord
  2011-10-11 22:10     ` Phil Hord
  0 siblings, 1 reply; 4+ messages in thread
From: Phil Hord @ 2011-10-11 20:58 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Johannes Schindelin, git

On Tue, Oct 11, 2011 at 4:25 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> @@ -868,8 +868,8 @@ static int is_gitfile(const char *url)
>>               return 0;
>>       if (!S_ISREG(st.st_mode))
>>               return 0;
>> -     if (st.st_size < 10 || st.st_size > PATH_MAX)
>> -             return 1;
>> +     if (st.st_size < 10 || st.st_size > 9 + PATH_MAX)
>> +             return 0;
>
> We are asked if the file is likely to be a single-liner "gitfile: <path>",
> and were answering yes when it is a very short file (less than 10 bytes)
> that cannot possibly even contain "gitfile: " prefix.
>
> I suspect that we can and should get rid of the "cannot be very long"
> check altogether---we do open and check the file, and after all it is not
> like we are throwing different strings as "url" argument to this function
> at random and this function needs heuristics to reject bogus input
> early. The argument is an input from the user.
>
> Quite an embarrasing bug. Thanks for spotting.

Yes, and it's _my_ embarrassing bug.  I've caught this and have it in
a re-roll, but I got mired up and haven't submitted it again.  I'll
try to do so today.

Phil

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix is_gitfile() for files larger than PATH_MAX
  2011-10-11 20:58   ` Phil Hord
@ 2011-10-11 22:10     ` Phil Hord
  0 siblings, 0 replies; 4+ messages in thread
From: Phil Hord @ 2011-10-11 22:10 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Johannes Schindelin, git

On Tue, Oct 11, 2011 at 4:58 PM, Phil Hord <phil.hord@gmail.com> wrote:
> I've caught this and have it in
> a re-roll, but I got mired up and haven't submitted it again.  I'll
> try to do so today.

On 2nd thought, my other changes are cleanup and not so much a re-roll
of this (except for a couple of code style edits pointed out by Junio,
but I guess those can slide).

I'll send the cleanups and generalities in another patch.

Thanks for the catch, Johannes.

Phil

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-10-11 22:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-11 19:25 [PATCH] Fix is_gitfile() for files larger than PATH_MAX Johannes Schindelin
2011-10-11 20:25 ` Junio C Hamano
2011-10-11 20:58   ` Phil Hord
2011-10-11 22:10     ` Phil Hord

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox