diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-10-08 15:18:10 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-10-08 15:41:08 +0200 |
commit | 84874785c2e226002bb05a42c704ed2d18b99508 (patch) | |
tree | 596aedbabefc6c35d445478bccdcfc58af8a5b0f /networking/httpd.c | |
parent | 50c5b36dd7a7c13fabb4afa428c1556d25401324 (diff) | |
download | busybox-w32-84874785c2e226002bb05a42c704ed2d18b99508.tar.gz busybox-w32-84874785c2e226002bb05a42c704ed2d18b99508.tar.bz2 busybox-w32-84874785c2e226002bb05a42c704ed2d18b99508.zip |
httpd: if range is not specified, correctly fall back to read/write loop
range_start was staying -1, and comparison meant to detect
"is it the first sendfile that failed, or not the first?"
was making incorrect decision. The result: nothing is sent.
function old new delta
send_file_and_exit 865 877 +12
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to '')
-rw-r--r-- | networking/httpd.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/networking/httpd.c b/networking/httpd.c index c038293e3..31c8489d3 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -1878,14 +1878,17 @@ static NOINLINE void send_file_and_exit(const char *url, int what) | |||
1878 | send_headers(HTTP_OK); | 1878 | send_headers(HTTP_OK); |
1879 | #if ENABLE_FEATURE_USE_SENDFILE | 1879 | #if ENABLE_FEATURE_USE_SENDFILE |
1880 | { | 1880 | { |
1881 | off_t offset = (range_start < 0) ? 0 : range_start; | 1881 | off_t offset; |
1882 | if (range_start < 0) | ||
1883 | range_start = 0; | ||
1884 | offset = range_start; | ||
1882 | while (1) { | 1885 | while (1) { |
1883 | /* sz is rounded down to 64k */ | 1886 | /* sz is rounded down to 64k */ |
1884 | ssize_t sz = MAXINT(ssize_t) - 0xffff; | 1887 | ssize_t sz = MAXINT(ssize_t) - 0xffff; |
1885 | IF_FEATURE_HTTPD_RANGES(if (sz > range_len) sz = range_len;) | 1888 | IF_FEATURE_HTTPD_RANGES(if (sz > range_len) sz = range_len;) |
1886 | count = sendfile(STDOUT_FILENO, fd, &offset, sz); | 1889 | count = sendfile(STDOUT_FILENO, fd, &offset, sz); |
1887 | if (count < 0) { | 1890 | if (count < 0) { |
1888 | if (offset == range_start) | 1891 | if (offset == range_start) /* was it the very 1st sendfile? */ |
1889 | break; /* fall back to read/write loop */ | 1892 | break; /* fall back to read/write loop */ |
1890 | goto fin; | 1893 | goto fin; |
1891 | } | 1894 | } |