{"thread":{"id":"41657","subject":"Problem with git-http-backend.exe as iis cgi","startedAt":"2016-03-10T07:28:50Z","lastAt":"2016-06-22T07:00:04Z","messageCount":6,"participants":["Florian Manschwetus","Chris Packham","Konstantin Khomoutov","Junio C Hamano","Johannes Schindelin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"280531","messageId":"F0F5A56A22F20D4CB4A03BB8D6658797E260E0E3@SERVER2011.CS-SOFTWARE.local","threadId":"41657","inReplyTo":null,"subject":"Problem with git-http-backend.exe as iis cgi","fromName":"Florian Manschwetus","fromEmail":"manschwetus@cs-software-gmbh.de","sentAt":"2016-03-10T07:28:50Z","receivedAt":"2016-03-10T07:28:50Z","isPatch":false,"sender":{"key":"manschwetus@cs-software-gmbh.de","avatar":null},"body":"Moin,\nI tried to setup git-http-backend with iis, as iis provides proper impersonation for cgi under windows, which leads to have the filesystem access performed with the logon user, therefore the webserver doesn't need generic access to the files.\nI stumbled across a problem, ending up with post requests hanging forever.\nAfter some investigation I managed to get it work by wrapping the http-backend into a bash script, giving a lot of control about the environmental things, I was unable to solve within IIS configuration.\nThe workaround, I use currently, is to use \"/bin/head -c ${CONTENT_LENGTH} | ./git-http-backend.exe\", which directly shows the issue.\nGit http-backend should check if CONTENT_LENGTH is set to something reasonable (e.g. >0) and should in this case read only CONTENT_LENGTH bytes from stdin, instead of reading till EOF what I suspect it is doing currently.\n\nMit freundlichen Grüßen / With kind regards\nFlorian Manschwetus\n\nCS Software Concepts and Solutions GmbH\nGeschäftsführer / Managing director: Dr. Werner Alexi \nAmtsgericht Wiesbaden HRB 10004 (Commercial registry)\nSchiersteiner Straße 31\nD-65187 Wiesbaden\nGermany\n"},{"id":"289663","messageId":"20160310155522.1dee53cf95fead8cfd4e178a@domain007.com","threadId":"41657","inReplyTo":"F0F5A56A22F20D4CB4A03BB8D6658797E260E0E3@SERVER2011.CS-SOFTWARE.local","subject":"Re: Problem with git-http-backend.exe as iis cgi","fromName":"Konstantin Khomoutov","fromEmail":"kostix+git@007spb.ru","sentAt":"2016-03-10T12:55:22Z","receivedAt":"2016-03-10T12:55:22Z","isPatch":false,"sender":{"key":"kostix+git@007spb.ru","avatar":null},"body":"On Thu, 10 Mar 2016 07:28:50 +0000\nFlorian Manschwetus <manschwetus@cs-software-gmbh.de> wrote:\n\n> I tried to setup git-http-backend with iis, as iis provides proper\n> impersonation for cgi under windows, which leads to have the\n> filesystem access performed with the logon user, therefore the\n> webserver doesn't need generic access to the files. I stumbled across\n> a problem, ending up with post requests hanging forever. After some\n> investigation I managed to get it work by wrapping the http-backend\n> into a bash script, giving a lot of control about the environmental\n> things, I was unable to solve within IIS configuration. The\n> workaround, I use currently, is to use \"/bin/head -c\n> ${CONTENT_LENGTH} | ./git-http-backend.exe\", which directly shows the\n> issue. Git http-backend should check if CONTENT_LENGTH is set to\n> something reasonable (e.g. >0) and should in this case read only\n> CONTENT_LENGTH bytes from stdin, instead of reading till EOF what I\n> suspect it is doing currently.\n\nThe rfc [1] states in its section 4.2:\n\n| A request-body is supplied with the request if the CONTENT_LENGTH is\n| not NULL.  The server MUST make at least that many bytes available\n| for the script to read.  The server MAY signal an end-of-file\n| condition after CONTENT_LENGTH bytes have been read or it MAY supply\n| extension data.  Therefore, the script MUST NOT attempt to read more\n| than CONTENT_LENGTH bytes, even if more data is available.  However,\n| it is not obliged to read any of the data.\n\nSo yes, if Git currently reads until EOF, it's an error.\nThe correct way would be:\n\n1) Check to see if the CONTENT_LENGTH variable is available in the\n   environment.  If no, read nothing.\n\n2) Otherwise read as many bytes it specifies, and no more.\n\n1. https://www.ietf.org/rfc/rfc3875\n"},{"id":"282027","messageId":"F0F5A56A22F20D4CB4A03BB8D6658797E261A10C@SERVER2011.CS-SOFTWARE.local","threadId":"41657","inReplyTo":"20160310155522.1dee53cf95fead8cfd4e178a@domain007.com","subject":"AW: Problem with git-http-backend.exe as iis cgi","fromName":"Florian Manschwetus","fromEmail":"manschwetus@cs-software-gmbh.de","sentAt":"2016-03-29T06:01:38Z","receivedAt":"2016-03-29T06:01:38Z","isPatch":false,"sender":{"key":"manschwetus@cs-software-gmbh.de","avatar":null},"body":"Hi,\nI put together a first patch for the issue.\n\nMit freundlichen Grüßen / With kind regards\nFlorian Manschwetus\n\nE-Mail: manschwetus@cs-software-gmbh.de\nTel.: +49-(0)611-8908534\n \nCS Software Concepts and Solutions GmbH\nGeschäftsführer / Managing director: Dr. Werner Alexi \nAmtsgericht Wiesbaden HRB 10004 (Commercial registry)\nSchiersteiner Straße 31\nD-65187 Wiesbaden\nGermany\nTel.: 0611/8908555\n\n\n-----Ursprüngliche Nachricht-----\nVon: Konstantin Khomoutov [mailto:kostix+git@007spb.ru] \nGesendet: Donnerstag, 10. März 2016 13:55\nAn: Florian Manschwetus\nCc: git@vger.kernel.org\nBetreff: Re: Problem with git-http-backend.exe as iis cgi\n\nOn Thu, 10 Mar 2016 07:28:50 +0000\nFlorian Manschwetus <manschwetus@cs-software-gmbh.de> wrote:\n\n> I tried to setup git-http-backend with iis, as iis provides proper \n> impersonation for cgi under windows, which leads to have the \n> filesystem access performed with the logon user, therefore the \n> webserver doesn't need generic access to the files. I stumbled across \n> a problem, ending up with post requests hanging forever. After some \n> investigation I managed to get it work by wrapping the http-backend \n> into a bash script, giving a lot of control about the environmental \n> things, I was unable to solve within IIS configuration. The \n> workaround, I use currently, is to use \"/bin/head -c ${CONTENT_LENGTH} \n> | ./git-http-backend.exe\", which directly shows the issue. Git \n> http-backend should check if CONTENT_LENGTH is set to something \n> reasonable (e.g. >0) and should in this case read only CONTENT_LENGTH \n> bytes from stdin, instead of reading till EOF what I suspect it is \n> doing currently.\n\nThe rfc [1] states in its section 4.2:\n\n| A request-body is supplied with the request if the CONTENT_LENGTH is \n| not NULL.  The server MUST make at least that many bytes available for \n| the script to read.  The server MAY signal an end-of-file condition \n| after CONTENT_LENGTH bytes have been read or it MAY supply extension \n| data.  Therefore, the script MUST NOT attempt to read more than \n| CONTENT_LENGTH bytes, even if more data is available.  However, it is \n| not obliged to read any of the data.\n\nSo yes, if Git currently reads until EOF, it's an error.\nThe correct way would be:\n\n1) Check to see if the CONTENT_LENGTH variable is available in the\n   environment.  If no, read nothing.\n\n2) Otherwise read as many bytes it specifies, and no more.\n\n1. https://www.ietf.org/rfc/rfc3875\n\n\n--- http-backend.c.orig\t2016-03-29 07:29:32.694722500 +0200\n+++ http-backend.c\t2016-03-29 07:58:50.801482700 +0200\n@@ -277,16 +277,32 @@\n  */\n static ssize_t read_request(int fd, unsigned char **out)\n {\n-\tsize_t len = 0, alloc = 8192;\n-\tunsigned char *buf = xmalloc(alloc);\n+\tunsigned char *buf = null;\n+\tsize_t len = 0;\n+\t/* get request size */\n+\tsize_t req_len = git_env_ulong(\"CONTENT_LENGTH\",\n+\t\t\t\t\t   0);\n+\n+\t/* check request size */\n+\tif (max_request_buffer < req_len) {\n+\t\tdie(\"request was larger than our maximum size (%lu);\"\n+\t\t\t    \" try setting GIT_HTTP_MAX_REQUEST_BUFFER\",\n+\t\t\t    max_request_buffer);\n+\t}\n+\n+\tif (req_len <= 0) {\n+\t\t*out = null;\n+\t\treturn 0;\n+\t}\n+\n+\t/* allocate buffer */\n+\tbuf = xmalloc(req_len)\n \n-\tif (max_request_buffer < alloc)\n-\t\tmax_request_buffer = alloc;\n \n \twhile (1) {\n \t\tssize_t cnt;\n \n-\t\tcnt = read_in_full(fd, buf + len, alloc - len);\n+\t\tcnt = read_in_full(fd, buf + len, req_len - len);\n \t\tif (cnt < 0) {\n \t\t\tfree(buf);\n \t\t\treturn -1;\n@@ -294,21 +310,18 @@\n \n \t\t/* partial read from read_in_full means we hit EOF */\n \t\tlen += cnt;\n-\t\tif (len < alloc) {\n+\t\tif (len < req_len) {\n+\t\t\t/* TODO request incomplete?? */\n+\t\t\t/* maybe just remove this block and condition along with the loop, */\n+\t\t\t/* if read_in_full is prooven reliable */\n \t\t\t*out = buf;\n \t\t\treturn len;\n+\t\t} else {\n+\t\t\t/* request complete */\n+\t\t\t*out = buf;\n+\t\t\treturn len;\n+\t\t\t\n \t\t}\n-\n-\t\t/* otherwise, grow and try again (if we can) */\n-\t\tif (alloc == max_request_buffer)\n-\t\t\tdie(\"request was larger than our maximum size (%lu);\"\n-\t\t\t    \" try setting GIT_HTTP_MAX_REQUEST_BUFFER\",\n-\t\t\t    max_request_buffer);\n-\n-\t\talloc = alloc_nr(alloc);\n-\t\tif (alloc > max_request_buffer)\n-\t\t\talloc = max_request_buffer;\n-\t\tREALLOC_ARRAY(buf, alloc);\n \t}\n }\n \n"},{"id":"282030","messageId":"CAFOYHZB6VEcXK9QV7puDMTsGQGdd8bqAHCsSnSn1Z5WuWs49qg@mail.gmail.com","threadId":"41657","inReplyTo":"F0F5A56A22F20D4CB4A03BB8D6658797E261A10C@SERVER2011.CS-SOFTWARE.local","subject":"Re: Problem with git-http-backend.exe as iis cgi","fromName":"Chris Packham","fromEmail":"judge.packham@gmail.com","sentAt":"2016-03-29T09:28:22Z","receivedAt":"2016-03-29T09:28:22Z","isPatch":false,"sender":{"key":"judge.packham@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155667?v=4"},"body":"Hi Florian\n\nOn Tue, Mar 29, 2016 at 7:01 PM, Florian Manschwetus\n<manschwetus@cs-software-gmbh.de> wrote:\n> Hi,\n> I put together a first patch for the issue.\n>\n> Mit freundlichen Grüßen / With kind regards\n> Florian Manschwetus\n>\n> E-Mail: manschwetus@cs-software-gmbh.de\n> Tel.: +49-(0)611-8908534\n>\n> CS Software Concepts and Solutions GmbH\n> Geschäftsführer / Managing director: Dr. Werner Alexi\n> Amtsgericht Wiesbaden HRB 10004 (Commercial registry)\n> Schiersteiner Straße 31\n> D-65187 Wiesbaden\n> Germany\n> Tel.: 0611/8908555\n>\n>\n> -----Ursprüngliche Nachricht-----\n> Von: Konstantin Khomoutov [mailto:kostix+git@007spb.ru]\n> Gesendet: Donnerstag, 10. März 2016 13:55\n> An: Florian Manschwetus\n> Cc: git@vger.kernel.org\n> Betreff: Re: Problem with git-http-backend.exe as iis cgi\n>\n> On Thu, 10 Mar 2016 07:28:50 +0000\n> Florian Manschwetus <manschwetus@cs-software-gmbh.de> wrote:\n>\n>> I tried to setup git-http-backend with iis, as iis provides proper\n>> impersonation for cgi under windows, which leads to have the\n>> filesystem access performed with the logon user, therefore the\n>> webserver doesn't need generic access to the files. I stumbled across\n>> a problem, ending up with post requests hanging forever. After some\n>> investigation I managed to get it work by wrapping the http-backend\n>> into a bash script, giving a lot of control about the environmental\n>> things, I was unable to solve within IIS configuration. The\n>> workaround, I use currently, is to use \"/bin/head -c ${CONTENT_LENGTH}\n>> | ./git-http-backend.exe\", which directly shows the issue. Git\n>> http-backend should check if CONTENT_LENGTH is set to something\n>> reasonable (e.g. >0) and should in this case read only CONTENT_LENGTH\n>> bytes from stdin, instead of reading till EOF what I suspect it is\n>> doing currently.\n>\n> The rfc [1] states in its section 4.2:\n>\n> | A request-body is supplied with the request if the CONTENT_LENGTH is\n> | not NULL.  The server MUST make at least that many bytes available for\n> | the script to read.  The server MAY signal an end-of-file condition\n> | after CONTENT_LENGTH bytes have been read or it MAY supply extension\n> | data.  Therefore, the script MUST NOT attempt to read more than\n> | CONTENT_LENGTH bytes, even if more data is available.  However, it is\n> | not obliged to read any of the data.\n>\n> So yes, if Git currently reads until EOF, it's an error.\n> The correct way would be:\n>\n> 1) Check to see if the CONTENT_LENGTH variable is available in the\n>    environment.  If no, read nothing.\n>\n> 2) Otherwise read as many bytes it specifies, and no more.\n>\n> 1. https://www.ietf.org/rfc/rfc3875\n\nYour patch description seems well thought out but if you want someone\nto notice it you should have a read of\nhttps://git.kernel.org/cgit/git/git.git/tree/Documentation/SubmittingPatches\n"},{"id":"289782","messageId":"xmqq60t2sd5c.fsf@gitster.mtv.corp.google.com","threadId":"41657","inReplyTo":"20160310155522.1dee53cf95fead8cfd4e178a@domain007.com","subject":"Re: Problem with git-http-backend.exe as iis cgi","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-06-21T16:46:39Z","receivedAt":"2016-06-21T16:47:16Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Konstantin Khomoutov <kostix+git@007spb.ru> writes:\n\n> On Thu, 10 Mar 2016 07:28:50 +0000\n> Florian Manschwetus <manschwetus@cs-software-gmbh.de> wrote:\n>\n>> I tried to setup git-http-backend with iis, as iis provides proper\n>> impersonation for cgi under windows, which leads to have the\n>> filesystem access performed with the logon user, therefore the\n>> webserver doesn't need generic access to the files. I stumbled across\n>> a problem, ending up with post requests hanging forever. After some\n>> investigation I managed to get it work by wrapping the http-backend\n>> into a bash script, giving a lot of control about the environmental\n>> things, I was unable to solve within IIS configuration. The\n>> workaround, I use currently, is to use \"/bin/head -c\n>> ${CONTENT_LENGTH} | ./git-http-backend.exe\", which directly shows the\n>> issue. Git http-backend should check if CONTENT_LENGTH is set to\n>> something reasonable (e.g. >0) and should in this case read only\n>> CONTENT_LENGTH bytes from stdin, instead of reading till EOF what I\n>> suspect it is doing currently.\n> ...\n> So yes, if Git currently reads until EOF, it's an error.\n\nThis sounded vaguely familiar.  Isn't this responding to a stale\nthread?\n\nhttp://thread.gmane.org/gmane.comp.version-control.git/290114\nproposed a patch along the line, and corrections to the patch was\nsuggested in the review, but it was not followed through, it seems.\n\n\n\n"},{"id":"289830","messageId":"alpine.DEB.2.20.1606220846030.10382@virtualbox","threadId":"41657","inReplyTo":"xmqq60t2sd5c.fsf@gitster.mtv.corp.google.com","subject":"Re: Problem with git-http-backend.exe as iis cgi","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2016-06-22T06:49:16Z","receivedAt":"2016-06-22T07:00:04Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Tue, 21 Jun 2016, Junio C Hamano wrote:\n\n> Konstantin Khomoutov <kostix+git@007spb.ru> writes:\n\n[purportedly on 10 Mar 13:55 2016, see $gmane/297739]\n\n> Isn't this responding to a stale thread?\n\nI was puzzled, too. I think the mail somehow got re-sent (and another one\nby Konst, too).\n\nCiao,\nDscho\n"}]}