{"thread":{"id":"28651","subject":"[PATCH] Fix is_gitfile() for files larger than PATH_MAX","startedAt":"2011-10-11T19:25:32Z","lastAt":"2011-10-11T22:10:32Z","messageCount":4,"participants":["Johannes Schindelin","Junio C Hamano","Phil Hord"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"177392","messageId":"alpine.DEB.1.00.1110111424010.32316@s15462909.onlinehome-server.info","threadId":"28651","inReplyTo":null,"subject":"[PATCH] Fix is_gitfile() for files larger than PATH_MAX","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2011-10-11T19:25:32Z","receivedAt":"2011-10-11T19:25:32Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nThe logic to check whether a file is a gitfile used the heuristics that\nthe file cannot be larger than PATH_MAX. But in that case it returned the\nwrong value. Our test cases do not cover this, as the bundle files\nproduced are smaller than PATH_MAX. Except on Windows.\n\nWhile at it, fix the faulty logic that the path stored in a gitfile cannot\nbe larger than PATH_MAX-sizeof(\"gitfile: \").\n\nProblem identified by running the test suite in msysGit, offending commit\nidentified by Jörg Rosenkranz.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\tThis patch should apply cleanly to 'next', which we track in\n\tmsysgit/git.\n\n\tThe task of adding a test case is something I leave to someone who\n\twants to get involved with Git development and needs an easy way\n\tin.\n\n transport.c |    4 ++--\n 1 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/transport.c b/transport.c\nindex f3195c0..57138d9 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -868,8 +868,8 @@ static int is_gitfile(const char *url)\n \t\treturn 0;\n \tif (!S_ISREG(st.st_mode))\n \t\treturn 0;\n-\tif (st.st_size < 10 || st.st_size > PATH_MAX)\n-\t\treturn 1;\n+\tif (st.st_size < 10 || st.st_size > 9 + PATH_MAX)\n+\t\treturn 0;\n \n \tfd = open(url, O_RDONLY);\n \tif (fd < 0)\n-- \n1.7.6.msysgit.0.584.g2cbf\n"},{"id":"177395","messageId":"7vy5wre0n7.fsf@alter.siamese.dyndns.org","threadId":"28651","inReplyTo":"alpine.DEB.1.00.1110111424010.32316@s15462909.onlinehome-server.info","subject":"Re: [PATCH] Fix is_gitfile() for files larger than PATH_MAX","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-10-11T20:25:32Z","receivedAt":"2011-10-11T20:25:32Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> The logic to check whether a file is a gitfile used the heuristics that\n> the file cannot be larger than PATH_MAX. But in that case it returned the\n> wrong value. Our test cases do not cover this, as the bundle files\n> produced are smaller than PATH_MAX. Except on Windows.\n>\n> While at it, fix the faulty logic that the path stored in a gitfile cannot\n> be larger than PATH_MAX-sizeof(\"gitfile: \").\n>\n> Problem identified by running the test suite in msysGit, offending commit\n> identified by Jörg Rosenkranz.\n>\n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n> \tThis patch should apply cleanly to 'next', which we track in\n> \tmsysgit/git.\n>\n> \tThe task of adding a test case is something I leave to someone who\n> \twants to get involved with Git development and needs an easy way\n> \tin.\n>\n>  transport.c |    4 ++--\n>  1 files changed, 2 insertions(+), 2 deletions(-)\n>\n> diff --git a/transport.c b/transport.c\n> index f3195c0..57138d9 100644\n> --- a/transport.c\n> +++ b/transport.c\n> @@ -868,8 +868,8 @@ static int is_gitfile(const char *url)\n>  \t\treturn 0;\n>  \tif (!S_ISREG(st.st_mode))\n>  \t\treturn 0;\n> -\tif (st.st_size < 10 || st.st_size > PATH_MAX)\n> -\t\treturn 1;\n> +\tif (st.st_size < 10 || st.st_size > 9 + PATH_MAX)\n> +\t\treturn 0;\n\nWe are asked if the file is likely to be a single-liner \"gitfile: <path>\",\nand were answering yes when it is a very short file (less than 10 bytes)\nthat cannot possibly even contain \"gitfile: \" prefix.\n\nI suspect that we can and should get rid of the \"cannot be very long\"\ncheck altogether---we do open and check the file, and after all it is not\nlike we are throwing different strings as \"url\" argument to this function\nat random and this function needs heuristics to reject bogus input\nearly. The argument is an input from the user.\n\nQuite an embarrasing bug. Thanks for spotting.\n"},{"id":"177397","messageId":"CABURp0ru7aCW_oUZO8eaFpau5DAHDgwWLqHSL1QMjbUDkqrANg@mail.gmail.com","threadId":"28651","inReplyTo":"7vy5wre0n7.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] Fix is_gitfile() for files larger than PATH_MAX","fromName":"Phil Hord","fromEmail":"phil.hord@gmail.com","sentAt":"2011-10-11T20:58:10Z","receivedAt":"2011-10-11T20:58:10Z","isPatch":true,"sender":{"key":"phil.hord@gmail.com","avatar":"https://avatars.githubusercontent.com/u/123908?v=4"},"body":"On Tue, Oct 11, 2011 at 4:25 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>> @@ -868,8 +868,8 @@ static int is_gitfile(const char *url)\n>>               return 0;\n>>       if (!S_ISREG(st.st_mode))\n>>               return 0;\n>> -     if (st.st_size < 10 || st.st_size > PATH_MAX)\n>> -             return 1;\n>> +     if (st.st_size < 10 || st.st_size > 9 + PATH_MAX)\n>> +             return 0;\n>\n> We are asked if the file is likely to be a single-liner \"gitfile: <path>\",\n> and were answering yes when it is a very short file (less than 10 bytes)\n> that cannot possibly even contain \"gitfile: \" prefix.\n>\n> I suspect that we can and should get rid of the \"cannot be very long\"\n> check altogether---we do open and check the file, and after all it is not\n> like we are throwing different strings as \"url\" argument to this function\n> at random and this function needs heuristics to reject bogus input\n> early. The argument is an input from the user.\n>\n> Quite an embarrasing bug. Thanks for spotting.\n\nYes, and it's _my_ embarrassing bug.  I've caught this and have it in\na re-roll, but I got mired up and haven't submitted it again.  I'll\ntry to do so today.\n\nPhil\n"},{"id":"177402","messageId":"CABURp0rS43hSg00SQQb0rY1R5Jvu4SGHHZr88q8AjV2MH1tkbQ@mail.gmail.com","threadId":"28651","inReplyTo":"CABURp0ru7aCW_oUZO8eaFpau5DAHDgwWLqHSL1QMjbUDkqrANg@mail.gmail.com","subject":"Re: [PATCH] Fix is_gitfile() for files larger than PATH_MAX","fromName":"Phil Hord","fromEmail":"phil.hord@gmail.com","sentAt":"2011-10-11T22:10:32Z","receivedAt":"2011-10-11T22:10:32Z","isPatch":true,"sender":{"key":"phil.hord@gmail.com","avatar":"https://avatars.githubusercontent.com/u/123908?v=4"},"body":"On Tue, Oct 11, 2011 at 4:58 PM, Phil Hord <phil.hord@gmail.com> wrote:\n> I've caught this and have it in\n> a re-roll, but I got mired up and haven't submitted it again.  I'll\n> try to do so today.\n\nOn 2nd thought, my other changes are cleanup and not so much a re-roll\nof this (except for a couple of code style edits pointed out by Junio,\nbut I guess those can slide).\n\nI'll send the cleanups and generalities in another patch.\n\nThanks for the catch, Johannes.\n\nPhil\n"}]}