journal-remote: verify entry length from header
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 7 Dec 2018 11:47:14 +0000 (12:47 +0100)
committerMartin Pitt <mpitt@debian.org>
Sun, 27 Jan 2019 21:33:07 +0000 (21:33 +0000)
commitf7a50b9b7a587e4263b24edca1d86b95dabb4554
tree4a9782c9bcd39436b0f625381d55fb795c816d4b
parent9b19ffbead5739af18d08efc38793a8f12d1b356
journal-remote: verify entry length from header

MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit

Calling mhd_respond(), which ulimately calls MHD_queue_response() is
ineffective at point, becuase MHD_queue_response() immediately returns
MHD_NO signifying an error, because the connection is in state
MHD_CONNECTION_CONTINUE_SENT.

As Christian Grothoff kindly explained:
> You are likely calling MHD_queue_repsonse() too late: once you are
> receiving upload_data, HTTP forces you to process it all. At this time,
> MHD has already sent "100 continue" and cannot take it back (hence you
> get MHD_NO!).
>
> In your request handler, the first time when you are called for a
> connection (and when hence *upload_data_size == 0 and upload_data ==
> NULL) you must check the content-length header and react (with
> MHD_queue_response) based on this (to prevent MHD from automatically
> generating 100 continue).

If we ever encounter this kind of error, print a warning and immediately
abort the connection. (The alternative would be to keep reading the data,
but ignore it, and return an error after we get to the end of data.
That is possible, but of course puts additional load on both the
sender and reciever, and doesn't seem important enough just to return
a good error message.)

Note that sending of the error does not work (the connection is always aborted
when MHD_queue_response is used with MHD_RESPMEM_MUST_FREE, as in this case)
with libµhttpd 0.59, but works with 0.61:
https://src.fedoraproject.org/rpms/libmicrohttpd/pull-request/1

(cherry picked from commit 7fdb237f5473cb8fc2129e57e8a0039526dcb4fd)
(cherry picked from commit c6d56141fad673a42b6b4eb186d2d217becca71c)

Gbp-Pq: Name journal-remote-verify-entry-length-from-header.patch
src/journal-remote/journal-remote-main.c