Commit graph

2172 commits

Author SHA1 Message Date
Lennart Poettering 0d76d772d1
Merge pull request #10536 from keszybz/serialize-fixes
Tests for the new serialization functions
2018-10-26 17:56:43 +02:00
Lennart Poettering 0ea63f7a7d
Merge pull request #10534 from poettering/cmdline-fixlets
proc-cmdline.c fixlets
2018-10-26 14:49:53 +02:00
Zbigniew Jędrzejewski-Szmek d8351049a8 Introduce fmkostemp_safe and use it in tests
No functional change.
2018-10-26 12:56:51 +02:00
Lennart Poettering 7d95229ba7 proc-cmdline: teach proc_cmdline_get_key() the same flags magic as proc_cmdline_parse() 2018-10-26 12:03:32 +02:00
Lennart Poettering cb447ff5cc proc-cmdline: use FLAGS_SET() where appropriate
This was mostly prompted by seeing the expression "in_initrd() && flags
& PROC_CMDLINE_RD_STRICT", which uses & and && without any brackets.
Let's make that a bit more readable and hide all doubts about operator
precedence.
2018-10-26 12:00:37 +02:00
Lennart Poettering 9de12b2ef4 proc-cmdline: use our usual syntax for denoting bit mask enums 2018-10-26 12:00:01 +02:00
Lennart Poettering 923db66a16 fileio: drop FOREACH_LINE(), it's not used anymore 2018-10-26 10:52:41 +02:00
Lennart Poettering d68c645bd3 core: rework serialization
Let's be more careful with what we serialize: let's ensure we never
serialize strings that are longer than LONG_LINE_MAX, so that we know we
can read them back with read_line(…, LONG_LINE_MAX, …) safely.

In order to implement this all serialization functions are move to
serialize.[ch], and internally will do line size checks. We'd rather
skip a serialization line (with a loud warning) than write an overly
long line out. Of course, this is just a second level protection, after
all the data we serialize shouldn't be this long in the first place.

While we are at it also clean up logging: while serializing make sure to
always log about errors immediately. Also, (void)ify all calls we don't
expect errors in (or catch errors as part of the general
fflush_and_check() at the end.
2018-10-26 10:52:41 +02:00
Zbigniew Jędrzejewski-Szmek f4478c98fa
Merge pull request #10522 from lnykryn/initrd_debug
Let's make systemd-debug-generator usable also in initrd
2018-10-26 10:08:39 +02:00
Lennart Poettering f267719c38 fd-util: optimize fd_get_path() a bit
journald calls fd_get_path() a lot (it probably shouldn't, there's some
room for improvement there, but I'll leave that for another time), hence
it's worth optimizing the call a bit, in particular as it's easy.

Previously we'd open the dir /proc/self/fd/ first, before reading the
symlink inside it. This means the whole function requires three system
calls: open(), readlinkat(), close(). The reason for doing it this way
is to distinguish the case when we see ENOENT because /proc is not
mounted and the case when the fd doesn't exist.

With this change we'll directly go for the readlink(), and only if that
fails do an access() to see if /proc is mounted at all.

This optimizes the common case (where the fd is valid and /proc
mounted), in favour of the uncommon case (where the fd doesn#t exist or
/proc is not mounted).
2018-10-25 21:37:14 +02:00
Lennart Poettering 8e060ec225 fs-util: increase start buffer size in readlinkat_malloc()
I noticed while profiling journald that we invoke readlinkat() a ton on
open /proc/self/fd/<fd>, and that the returned paths are more often than
not longer than the 99 chars used before, when we look at archived
journal files. This means for these cases we generally need to execute
two rather than one syscalls.

Let's increase the buffer size a tiny bit, so that we reduce the number
of syscalls executed. This is really a low-hanging fruit of
optimization.
2018-10-25 21:37:14 +02:00
Zbigniew Jędrzejewski-Szmek 05f339267e
Merge pull request #10378 from poettering/json-fuzz-fix
json: a comprehensive fix for oss-fuzz#10908
2018-10-25 16:25:39 +02:00
Lukas Nykryn ed58820d76 proc-cmdline: introduce PROC_CMDLINE_RD_STRICT
Our current set of flags allows an option to be either
use just in initrd or both in initrd and normal system.
This new flag is intended to be used in the case where
you want apply some settings just in initrd or just
in normal system.
2018-10-25 16:21:26 +02:00
Yu Watanabe 4e412d2684
string-util: fix prototype of explicit_bzero_safe() (#10513)
Follow-up for 87f5446311.
2018-10-25 11:41:55 +09:00
Lennart Poettering def34f63fe time-util: change parse_sec_fix_0() to accept "0s" for infinity too (#10501)
This function is about compatibility, nothing else, hence we should make
it properly compatible.

Fixes: #9556
2018-10-25 05:21:28 +09:00
Lennart Poettering 87f5446311 string-util: introduce explicit_zero_safe()
The only real difference is that this wrapper can deal with NULL
pointer arguments, but only if the length is also zero.

CID 1396277
2018-10-24 21:00:15 +02:00
Yu Watanabe f6a178e91d util: check overflow in parse_nsec() 2018-10-23 22:24:16 +09:00
Yu Watanabe 8079c90333 util: check overflow in parse_time() 2018-10-23 22:23:34 +09:00
Chris Down 3f1c1287a9 analyze: Add "timespan" command to dump time span in usec
This is useful for a couple of cases, I'm mostly interested in case #1:

1. Verifying "reasonable" values in a trivially scriptable way
2. Debugging unexpected time span parsing directly

Test Plan:

```
% build/systemd-analyze timespan 20
Original: 20
      μs: 20
   Human: 20us
% build/systemd-analyze timespan 20ms
Original: 20ms
      μs: 20000
   Human: 20ms
% build/systemd-analyze timespan 20z
Failed to parse time span '20z': Invalid argument
```
2018-10-23 14:26:51 +02:00
Yu Watanabe 80df8f2518 missing: support old linux/fou.h
linux/fou.h was introduced in 3.18.
FOU_ATTR_REMCSUM_NOPARTIAL was added in 4.0.
FOU_CMD_GET was added in 4.1.

Follow-up for 53cb501a13.
Fixes #10474.
2018-10-21 22:34:28 +09:00
Lennart Poettering a2689fa5fc
Merge pull request #9437 from poettering/sd-boot-count
many sd-boot/bootctl fixes, and a new "boot counting" concept, for automatic fallback to older kernels on persistent failures
2018-10-19 23:04:22 +02:00
Lennart Poettering 41159592f8
Merge pull request #10470 from yuwata/log-message-updates
Log message updates
2018-10-19 22:58:53 +02:00
Lennart Poettering 36695e880a add new systemd-bless-boot.service that marks boots as successful
This is the counterpiece to the boot counting implemented in
systemd-boot: if a boot is detected as successful we mark drop the
counter again from the booted snippet or kernel image.
2018-10-19 22:34:50 +02:00
Yu Watanabe 14cb109d45 tree-wide: replace 'unsigned int' with 'unsigned' 2018-10-19 22:19:12 +02:00
Yu Watanabe 011723a451 fs-util: include error cause in log message 2018-10-20 00:48:21 +09:00
Lennart Poettering 490c5a37cb tree-wide: some automatic coccinelle fixes (#10463)
Nothing fancy, just coccinelle doing its work.
2018-10-20 00:07:46 +09:00
Lennart Poettering 6ab1853953
Merge pull request #10460 from yuwata/setsockopt_int-more
tree-wide: use setsockopt_int() more
2018-10-19 10:12:00 +02:00
Yu Watanabe 84711d20b0
Merge pull request #10437 from poettering/env-util-love
some env-util.c love
2018-10-19 08:57:51 +09:00
Yu Watanabe b0b8c9a5a4
Merge pull request #10389 from poettering/nspawn-path-fix
nspawn $PATH execvpe() fix
2018-10-19 08:48:37 +09:00
Yu Watanabe 17acb7ef9a
Merge pull request #10450 from poettering/foreach-line-excorcism
FOREACH_LINE excorcism
2018-10-19 08:44:51 +09:00
Yu Watanabe 218b4609d0
Merge pull request #10447 from poettering/fgets-excorcism
let's get rid of fgets()
2018-10-19 08:36:01 +09:00
Yu Watanabe 9e5b649655 tree-wide: use setsockopt_int() more 2018-10-19 05:52:42 +09:00
Lennart Poettering b33fa02b2d util: drop const_int_one/const_int_zero again
There's only a single user remaining now that we have setsockopt_int(),
let's define those variables locally.

This more or less reverts 6d5e65f645.
2018-10-18 19:50:29 +02:00
Lennart Poettering 2ff48e981e tree-wide: introduce setsockopt_int() helper and make use of it everywhere
As suggested by @heftig:

6d5e65f645 (commitcomment-30938667)
2018-10-18 19:50:29 +02:00
Lennart Poettering 085f3d6416 json: add an assert_cc() check that validates _JSON_VARIANT_MAGIC_MAX 2018-10-18 16:44:51 +02:00
Lennart Poettering 7e61bd0f67 macro.h: include assert.h so that static_assert can be properly checked for
For the definition of assert_cc() we try to use static_assert and check
for it with "#ifdef". But that can only work if assert.h is imported
before. Hence let's do so.
2018-10-18 16:44:51 +02:00
Lennart Poettering d520d519f0 json: add support for using static const strings directly as JsonVariant objects
This is a nice little optimization when using static const strings: we
can now use them directly as JsonVariant objecs, without any additional
allocation.
2018-10-18 16:44:51 +02:00
Lennart Poettering 4fcb507a90 json: minor optimization
instead of comparing the magic JsonVariants one by one, let's simply
compare that they lie within a specific range.
2018-10-18 16:44:51 +02:00
Lennart Poettering d77e781fd0 json: when creating an object, insist that every second item is a string
After all, those are the keys, which have to be keys.
2018-10-18 16:44:51 +02:00
Lennart Poettering b2fa0d4fca json: enforce a maximum nesting depth for json variants
Simply as a safety precaution so that json objects we read are not
arbitrary amounts deep, so that code that processes json objects
recursively can't be easily exploited (by hitting stack limits).

Follow-up for oss-fuzz#10908

(Nice is that we can accomodate for this counter without increasing the
size of the JsonVariant object.)
2018-10-18 16:44:51 +02:00
Lennart Poettering a7efb03039 json: slightly reorder JsonVariant
Let's move things around a bit, so that the trailing unused whitespace
within the structure due to padding is placed together, so that it is
easier to use for new fields. (Found with pahole)
2018-10-18 16:44:51 +02:00
Lennart Poettering 4ae7e4e5d8 json: avoid stack allocation of long strings in a recursive function
Fixes: oss-fuzz#10908

https://oss-fuzz.com/v2/testcase-detail/5639441482252288
2018-10-18 16:44:51 +02:00
Lennart Poettering 92853e9bbe json: return a double when we shall return a double 2018-10-18 16:44:51 +02:00
Lennart Poettering a1559e3f53 json: use structured initialization all the way 2018-10-18 16:44:51 +02:00
Lennart Poettering 8f7329ac27 exec-util: errors are reported by non-zero, not negative by putenv() 2018-10-18 16:40:12 +02:00
Lennart Poettering 8d2b9d14c4 time-util: FOREACH_LINE excorcism 2018-10-18 16:23:45 +02:00
Lennart Poettering 7e7a16a00e process-util: FOREACH_LINE excorcism 2018-10-18 16:23:45 +02:00
Lennart Poettering f5af75eaec mount-util: FOREACH_LINE() excorcism 2018-10-18 16:23:45 +02:00
Lennart Poettering d2b39cb606 cgroup-util: FOREACH_LINE() excorcism 2018-10-18 16:23:45 +02:00
Lennart Poettering d3f9790c81 terminal-util: use fgetc() carefully instead of fread() 2018-10-18 13:32:34 +02:00