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>
Mon, 18 Feb 2019 13:54:04 +0000 (13:54 +0000)
commit34a16554c471e05090aed0eaabf48a3c7a94a3d2
tree7aa06a482753fd01278235bfdd86c76c32985b24
parentf483e76beac428e5d7eb8b1f7d60f6859b1c4522
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