diff options
author | Maxim Storchak <m.storchak@gmail.com> | 2020-12-29 17:29:05 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-12-29 23:03:32 +0100 |
commit | 04e0d8e579b289178b0303a92c705012237f4ca3 (patch) | |
tree | 80300504e397fd61011b43e2a8d91dda3a99f746 | |
parent | 29a9043b36c9ca5a5d6f10fc183c7b7de0f979c7 (diff) | |
download | busybox-w32-04e0d8e579b289178b0303a92c705012237f4ca3.tar.gz busybox-w32-04e0d8e579b289178b0303a92c705012237f4ca3.tar.bz2 busybox-w32-04e0d8e579b289178b0303a92c705012237f4ca3.zip |
httpd: fix offset for sendfile
If the Range: header is not present it the request,
the offset passed to sendfile is wrong,
and httpd falls back to the read-write loop.
function old new delta
send_file_and_exit 857 865 +8
handle_incoming_and_exit 2239 2230 -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 8/-9) Total: -1 bytes
Signed-off-by: Maxim Storchak <m.storchak@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/httpd.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/networking/httpd.c b/networking/httpd.c index 4346141ee..4c014bc71 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -1871,7 +1871,7 @@ static NOINLINE void send_file_and_exit(const char *url, int what) | |||
1871 | send_headers(HTTP_OK); | 1871 | send_headers(HTTP_OK); |
1872 | #if ENABLE_FEATURE_USE_SENDFILE | 1872 | #if ENABLE_FEATURE_USE_SENDFILE |
1873 | { | 1873 | { |
1874 | off_t offset = range_start; | 1874 | off_t offset = (range_start < 0) ? 0 : range_start; |
1875 | while (1) { | 1875 | while (1) { |
1876 | /* sz is rounded down to 64k */ | 1876 | /* sz is rounded down to 64k */ |
1877 | ssize_t sz = MAXINT(ssize_t) - 0xffff; | 1877 | ssize_t sz = MAXINT(ssize_t) - 0xffff; |
@@ -2486,8 +2486,8 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) | |||
2486 | if (STRNCASECMP(iobuf, "Range:") == 0) { | 2486 | if (STRNCASECMP(iobuf, "Range:") == 0) { |
2487 | /* We know only bytes=NNN-[MMM] */ | 2487 | /* We know only bytes=NNN-[MMM] */ |
2488 | char *s = skip_whitespace(iobuf + sizeof("Range:")-1); | 2488 | char *s = skip_whitespace(iobuf + sizeof("Range:")-1); |
2489 | if (is_prefixed_with(s, "bytes=")) { | 2489 | s = is_prefixed_with(s, "bytes="); |
2490 | s += sizeof("bytes=")-1; | 2490 | if (s) { |
2491 | range_start = BB_STRTOOFF(s, &s, 10); | 2491 | range_start = BB_STRTOOFF(s, &s, 10); |
2492 | if (s[0] != '-' || range_start < 0) { | 2492 | if (s[0] != '-' || range_start < 0) { |
2493 | range_start = -1; | 2493 | range_start = -1; |