On Thu, Nov 23, 2017 at 6:45 PM, Max Kirillov <max@xxxxxxxxxx> wrote: > [PATCH] http-backend: respect CONTENT_LENGTH as specified by rfc3875 The "RFC" seems to be missing from the subject line of this unpolished patch. > http-backend reads whole input until EOF. However, the RFC 3875 specifies > that a script must read only as many bytes as specified by CONTENT_LENGTH > environment variable. This causes hang under IIS/Windows, for example. By "_this_ causes a hang", I presume you mean "not respecting CONTENT_LENGTH causes a hang"? Perhaps that could be spelled out explicitly. > Make http-backend read only CONTENT_LENGTH bytes, if it's defined, rather than > the whole input until EOF. If the varibale is not defined, keep older behavior s/varibale/variable/ > of reading until EOF because it is used to support chunked transfer-encoding. > > Signed-off-by: Florian Manschwetus <manschwetus@xxxxxxxxxxxxxxxxxxx> > Authored-by: Florian Manschwetus <manschwetus@xxxxxxxxxxxxxxxxxxx> > Fixed-by: Max Kirillov <max@xxxxxxxxxx> > Signed-off-by: Max Kirillov <max@xxxxxxxxxx> > --- > diff --git a/http-backend.c b/http-backend.c > @@ -317,6 +317,76 @@ static ssize_t read_request(int fd, unsigned char **out) > +/* > + * replacement for original read_request, now renamed to read_request_eof, > + * honoring given content_length (req_len), > + * provided by new wrapper function read_request > + */ This comment has value only to someone who knew what the code was like before this change, and it merely repeats what is already implied by the commit message, rather than providing any valuable information about this new function itself. Therefore, it should be dropped. > +static ssize_t read_request_fix_len(int fd, size_t req_len, unsigned char **out) Wrong data type: s/size_t req_len/ssize_t req_len/ Also: s/fix/fixed/ > +{ > + unsigned char *buf = NULL; > + size_t len = 0; > + > + /* check request size */ Comment merely repeats what code says, thus has no value. Please drop. > + if (max_request_buffer < req_len) { > + die("request was larger than our maximum size (%lu);" > + " try setting GIT_HTTP_MAX_REQUEST_BUFFER", > + max_request_buffer); This error message neglects to say what the request size was. Such information would be useful given that it suggests bumping GIT_HTTP_MAX_REQUEST_BUFFER to a larger value. > + } > + > + if (req_len <= 0) { > + *out = NULL; > + return 0; > + } > + > + /* allocate buffer */ Drop valueless comment. > + buf = xmalloc(req_len); > + > + Style: Too many blank lines. > + while (1) { > + ssize_t cnt; > + > + cnt = read_in_full(fd, buf + len, req_len - len); > + if (cnt < 0) { > + free(buf); > + return -1; > + } > + > + /* partial read from read_in_full means we hit EOF */ > + len += cnt; > + if (len < req_len) { > + /* TODO request incomplete?? */ > + /* maybe just remove this block and condition along with the loop, */ > + /* if read_in_full is prooven reliable */ s/prooven/proven/ > + *out = buf; > + return len; > + } else { > + /* request complete */ > + *out = buf; > + return len; > + > + } > + } What is the purpose of the while(1) loop? Every code path inside the loop returns, so it will never execute more than once. Likewise, why is 'len' needed? Rather than writing an entirely new "read" function, how about just modifying the existing read_request() to optionally limit the read to a specified number of bytes? > +} > + > +/** > + * wrapper function, whcih determines based on CONTENT_LENGTH value, s/whcih/which/ Also, the placement of commas needs some attention. > + * to > + * - use old behaviour of read_request, to read until EOF > + * => read_request_eof(...) > + * - just read CONTENT_LENGTH-bytes, when provided > + * => read_request_fix_len(...) > + */ When talking about "old behavior", this comment is repeating information more suitable to the commit message (and effectively already covered there); information which only has value to someone who knew what the old code/behavior was like. The rest of this comment is merely repeating what the code itself already says, thus adds no value, so should be dropped. > +static ssize_t read_request(int fd, unsigned char **out) > +{ > + /* get request size */ Drop valueless comment. > + ssize_t req_len = git_env_ssize_t("CONTENT_LENGTH", -1); > + if (req_len < 0) > + return read_request_eof(fd, out); > + else > + return read_request_fix_len(fd, req_len, out); > +}