chiark / gitweb /
basic/log: make sure header is printed correctly, add test
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 22 Feb 2018 22:55:14 +0000 (23:55 +0100)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:59:04 +0000 (07:59 +0200)
commitb5d08e33f89723a18c8452f084551192dbec31b1
tree85637e36e15cdc9a16924a96edf2a66568e3560a
parent623a5e5a3a0c054d09b64f92bf4f5f257b5d5ff5
basic/log: make sure header is printed correctly, add test

If log_do_header() was called with overly long parameters, it'd generate
improper output. Essentially, it'd be truncated at random point, in particular
missing a newline at the end, so it'd run with the next field, usually MESSAGE=.

log_do_header is called with parameters from compiled code (file name, lien
nubmer, etc), so in practice this was unlikely to ever be a problem, but it is
possible. In particular, if systemd was compiled from sources in some deeply
nested directory (which happens for example in mock and other build roots), the
filename could be very long.

As a safety measure, let's truncate all parameters to 256 bytes. So we have
5 fields which are 256 bytes (plus the field name prefix), and a few other
fields with fixed width. This must always fit in the 2048 byte buffer.
I don't think there's much gain in calculating the required length precisely,
since it's a lot of fields and a few bytes allocated on the stack don't matter.
src/basic/log.c
src/test/test-log.c