git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] http-backend: respect CONTENT_LENGTH as specified by rfc3875

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Nov 24, 2017, 01:30 UTC
Message-ID
<CAPig+cQEaqaOTcC=5pZZmZNs_QQQ0vBRbzczyM3ZXXi+ZHW4XA@mail.gmail.com>
In-Reply-To
<20171123234511.574-1-max@max630.net>
On Thu, Nov 23, 2017 at 6:45 PM, Max Kirillov <max@max630.net> 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/
Show 14 quoted lines
> of reading until EOF because it is used to support chunked transfer-encoding.
>
> Signed-off-by: Florian Manschwetus <manschwetus@cs-software-gmbh.de>
> Authored-by: Florian Manschwetus <manschwetus@cs-software-gmbh.de>
> Fixed-by: Max Kirillov <max@max630.net>
> Signed-off-by: Max Kirillov <max@max630.net>
> ---
> 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/
Show 5 quoted lines
> +{
> +       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.

Show 8 quoted lines
> +       }
> +
> +       if (req_len <= 0) {
> +               *out = NULL;
> +               return 0;
> +       }
> +
> +       /* allocate buffer */
Drop valueless comment.
> +       buf = xmalloc(req_len);
> +
> +
Style: Too many blank lines.
Show 15 quoted 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/
Show 9 quoted lines
> +                       *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.
Show 6 quoted lines
> + * 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.
Show 6 quoted lines
> +       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);
> +}
Previous: Max KirillovNext: Max Kirillov
Message 6 of 50 in “Fix http-backend reading till EOF, ignoring CONTENT_LENGTH, violating rfc3875 -- WAS: Problem with git-http-backend.exe as iis cgi”
  1. Fix http-backend reading till EOF, ignoring CONTENT_LENGTH, violating rfc3875 -- WAS: Problem with git-http-backend.exe as iis cgiFlorian Manschwetus, Mar 29, 2016
  2. Jeff KingMar 29, 2016
  3. AW: [PATCH] Fix http-backend reading till EOF, ignoring CONTENT_LENGTH, violating rfc3875 -- WAS: Problem with git-http-backend.exe as iis cgiFlorian Manschwetus, Mar 30, 2016
  4. Jeff KingApr 1, 2016
  5. http-backend: respect CONTENT_LENGTH as specified by rfc3875Max Kirillov, Nov 23, 2017
  6. Eric SunshineNov 24, 2017
  7. Max KirillovNov 25, 2017
  8. Eric SunshineNov 26, 2017
  9. Max KirillovNov 26, 2017
  10. Junio C HamanoNov 24, 2017
  11. AW: [PATCH] http-backend: respect CONTENT_LENGTH as specified by rfc3875Florian Manschwetus, Nov 24, 2017
  12. Max KirillovNov 26, 2017
  13. 0/2 http-backend: respect CONTENT_LENGTH as specified by rfc3875Max Kirillov, Nov 26, 2017
  14. 1/2 http-backend: respect CONTENT_LENGTH as specified by rfc3875Max Kirillov, Nov 26, 2017
  15. 2/2 t5560-http-backend-noserver.sh: add CONTENT_LENGTH casesMax Kirillov, Nov 26, 2017
  16. 0/2 http-backend: respect CONTENT_LENGTH as specified by rfc3875Max Kirillov, Nov 26, 2017
  17. 2/2 t5560-http-backend-noserver.sh: add CONTENT_LENGTH casesMax Kirillov, Nov 26, 2017
  18. 1/2 http-backend: respect CONTENT_LENGTH as specified by rfc3875Max Kirillov, Nov 26, 2017
  19. Junio C HamanoNov 26, 2017
  20. Max KirillovNov 26, 2017
  21. Junio C HamanoNov 26, 2017
  22. Max KirillovNov 26, 2017
  23. 0/2 http-backend: respect CONTENT_LENGTH as specified by rfc3875Max Kirillov, Nov 26, 2017
  24. 1/2 http-backend: respect CONTENT_LENGTH as specified by rfc3875Max Kirillov, Nov 26, 2017
  25. Eric SunshineNov 26, 2017
  26. Jeff KingNov 29, 2017
  27. Junio C HamanoDec 3, 2017
  28. Jeff KingDec 3, 2017
  29. Junio C HamanoDec 3, 2017
  30. AW: [PATCH v6 1/2] http-backend: respect CONTENT_LENGTH as specified by rfc3875Florian Manschwetus, Dec 4, 2017
  31. Jeff KingDec 4, 2017
  32. 2/2 t5560-http-backend-noserver.sh: add CONTENT_LENGTH casesMax Kirillov, Nov 26, 2017
  33. Eric SunshineNov 26, 2017
  34. Max KirillovNov 26, 2017
  35. Jeff KingNov 29, 2017
  36. Max KirillovNov 29, 2017
  37. Junio C HamanoDec 3, 2017
  38. Junio C HamanoNov 27, 2017
  39. Junio C HamanoNov 27, 2017
  40. Max KirillovNov 29, 2017
  41. Junio C HamanoDec 3, 2017
  42. Need to add test artifacts to .gitignoreDan Jacques, Dec 12, 2017
  43. t/helper: Move sources to t/helper-src; gitignore any files in t/helperStefan Beller, Dec 12, 2017
  44. Junio C HamanoDec 12, 2017
  45. t/helper: ignore everything but sourcesStefan Beller, Dec 12, 2017
  46. Junio C HamanoDec 12, 2017
  47. t/helper: ignore everything but sourcesStefan Beller, Dec 13, 2017
  48. Todd ZullingerDec 12, 2017
  49. Junio C HamanoDec 19, 2017
  50. Max KirillovDec 20, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.