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)
committerMichael Biebl <biebl@debian.org>
Sat, 12 Jan 2019 20:49:44 +0000 (20:49 +0000)
commit697720b9fc238fa0cb03c0d3b4230df56ce6ddb4
tree0aa472f3b9d9c55c4d03d4dda281d30aa047d7ac
parentbd3a7e6325db59d947cdb652149fb70924a00416
journal-remote: verify entry length from header

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