]> git.ipfire.org Git - thirdparty/systemd.git/commit
journal-remote: use macro wrapper instead of alloca to extend string
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 12 Jan 2024 15:37:04 +0000 (16:37 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 15 Jan 2024 17:04:23 +0000 (18:04 +0100)
commit320ff932658fb1e3c2aeb1832ff6c10d755e5a56
tree09289fad44f7027db54a8e3625871d16b0edeef9
parent204594ecf1bc03f0e620e10d8beaec439e7fd6ab
journal-remote: use macro wrapper instead of alloca to extend string

We would use alloca to extend the format string with "\n". We do this
automatically in order to not forget appending the newline everywhere.
We can simplify the whole thing by using a macro to append the newline instead,
which means that we don't need to copy the string.

Because we concatenate the string argument with another literal string, we know
it must a literal string. Thus it's not a problem that it is "evaluated" two
times.

Quoting Hristo Venev:
> Since commit f5e757f1ce84c1d6ae932cf2b604238fb4cedc00, mhd_respond() adds a
> newline to its argument before passing it on to mhd_respond_internal(). This
> is done via an alloca()-allocated buffer. However, MHD_RESPMEM_PERSISTENT is
> given as a flag to MHD_create_response_from_buffer(), leading to a
> use-after-free later when the response is sent. Replacing
> MHD_RESPMEM_PERSISTENT with MHD_RESPMEM_MUST_COPY appears to fix the issue.

MHD_RESPMEM_MUST_COPY would work, but we also use mhd_respond() for mhd_oom(),
and we don't want to allocate in an oom scenario in order to maximize the
possibility that an answer will be delivered. Using the macro magic makes this
nicer and we get rid of the code doing alloca.

Fixes an issue reported by Hristo Venev.
Fixes https://github.com/systemd/systemd/issues/9858.
src/journal-remote/microhttpd-util.c
src/journal-remote/microhttpd-util.h