Commit graph

1556 commits

Author SHA1 Message Date
Yu Watanabe f330408d62 tree-wide: drop empty lines in comments 2018-07-23 08:44:24 +02:00
Yu Watanabe 2e7e8e34aa sd-bus: make bus_slot_disconnect() also unref the slot object
This makes bus_slot_disconnect() unref the slot object from bus when
`unref == true` and it is floating, as the function removes the
reference from the relevant bus object.

This reverts 20d4ee2cbc, as it
introduces #9604.

Fixes #9604.
2018-07-18 20:54:19 +02:00
Zbigniew Jędrzejewski-Szmek 6d77a30c09 bus: add comment to explain assert 2018-07-18 16:36:37 +02:00
Zbigniew Jędrzejewski-Szmek 7ae8edcd03 bus: move BUS_DONT_DESTROY calls after asserts
It's not useful to bump the reference count before checking if the object is
NULL. Thanks to d40f5cc498 we can do this ;).

Related to https://bugzilla.redhat.com/show_bug.cgi?id=1576084,
https://bugzilla.redhat.com/show_bug.cgi?id=1575340,
https://bugzilla.redhat.com/show_bug.cgi?id=1575350. I'm not sure why those two
people hit this code path, while most people don't. At least we won't abort.
2018-07-18 12:16:33 +02:00
Filipe Brandenburger 3f10c66270 bus-socket: Fix line_begins() to accept word matching full string
The switch to memory_startswith() changed the logic to only look for a space or
NUL byte after the matched word, but matching the full size should also be
acceptable.

This changed the behavior of parsing of "AUTH\r\n", where m will be set to 4,
since even though the word will match, the check for it being followed by ' '
or NUL will make line_begins() return false.

Tested:

- Using netcat to connect to the private socket directly:
  $ echo -ne '\0AUTH\r\n' | sudo nc -U /run/systemd/private
  REJECTED EXTERNAL ANONYMOUS

- Running the Ignition blackbox test:
  $ sudo sh -c 'PATH=$PWD/bin/amd64:$PATH ./tests.test'
  PASS

Fixes: d27b725abf
2018-07-17 21:42:20 +02:00
Yu Watanabe 385b2eb262 sd-bus: make BUS_DEFAULT_TIMEOUT configurable
This adds sd_bus_{get,set}_method_call_timeout().
If the timeout is not set or set to 0, then the timeout value is
parsed from $SYSTEMD_BUS_TIMEOUT= environment variable. If the
environment variable is not set, then built-in timeout is used.
2018-07-16 15:11:50 +02:00
Yu Watanabe 20d4ee2cbc sd-bus: unref slot->match_callback.install_slot when slot is disconnected
When a slot is disconnected, then slot->match_callback.install_slot
is also disconnected. So, bus_slot_disconnect() removes the install_slot
from the list of slots in bus, although it is a floating object.
This makes install_slot unreffed from bus when it is disconnected.

Fixes #9505 and #9510.
2018-07-13 20:07:43 +02:00
Yu Watanabe db2f8a2e8a tree-wide: add a space after (void) 2018-07-03 10:44:28 +02:00
Violet Halo 11ce0db2e2 sd-bus: publicize sd_bus_message_readv()
The D-Bus library supplies a va_list variant of
`sd_bus_message_append()` called `sd_bus_message_appendv()`,
but failed to provide a va_list variant of its opposite,
`sd_bus_message_read()`. This commit publicizes a previously static
function as `sd_bus_message_readv()`.
2018-06-29 11:45:40 +02:00
Yu Watanabe afb76fdbff tree-wide: drop double newline 2018-06-29 11:02:17 +09:00
Yu Watanabe 8f5dd8c094 tree-wide: drop empty comments 2018-06-29 11:00:30 +09:00
Yu Watanabe 845d247a3d tree-wide: use 'signed int' instead of 'int' for bit field variables
Suggested by LGTM: https://lgtm.com/rules/1506024027114/
2018-06-28 10:16:51 +02:00
Evegeny Vereshchagin 283c265387 sd-bus: stop using the result of an assignment as an operand of &&
This makes OBJECT_PATH_FOREACH_PREFIX consistent with PATH_FOREACH_PREFIX
and also fixes 7 alerts reported by LGTM at
ac0a087003/files/src/libsystemd/sd-bus/bus-objects.c?sort=name&dir=ASC&mode=heatmap&showExcluded=true#V1383
2018-06-28 13:17:29 +09:00
Yu Watanabe affaed1e55 sd-bus: fix implicit downcast of bitfield reported by LGTM 2018-06-27 13:28:28 +09:00
Zbigniew Jędrzejewski-Szmek 25612ecba4 tree-wide: drop copyright lines for more authors
Acks in https://github.com/systemd/systemd/issues/9320.
2018-06-22 16:39:45 +02:00
Lennart Poettering a6887cc03e tree-wide: drop MSG_NOSIGNAL flag from recvmsg() invocations
MSG_NOSIGNAL is only defined for sendmsg(), not for recvmsg(), hence
let's drop it's use, in particular as it appears to create problems on
older kernels. See:

https://lists.freedesktop.org/archives/systemd-devel/2018-June/040869.html
2018-06-20 16:12:55 +02:00
Zbigniew Jędrzejewski-Szmek d9b02e1697 tree-wide: drop copyright headers from frequent contributors
Fixes #9320.

for p in Shapovalov Chevalier Rozhkov Sievers Mack Herrmann Schmidt Rudenberg Sahani Landden Andersen Watanabe; do
  git grep -e 'Copyright.*'$p -l|xargs perl -i -0pe 's|/([*][*])?[*]\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\s*[*]([*][*])?/\n*|\n|gms; s|\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\n*|\n|gms'
done
2018-06-20 11:58:53 +02:00
Yu Watanabe 22509a8df0 sd-bus: fix typo in comment 2018-06-19 08:44:55 +02:00
Chris Lamb 3fe910794b Correct a number of trivial typos. 2018-06-18 22:44:44 +02:00
Zbigniew Jędrzejewski-Szmek 0cd41d4dff Drop my copyright headers
perl -i -0pe 's/\s*Copyright © .... Zbigniew Jędrzejewski.*?\n/\n/gms' man/*xml
git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/(#\n)?# +Copyright © [0-9, -]+ Zbigniew Jędrzejewski.*?\n//gms'
git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/\s*\/\*\*\*\s+Copyright © [0-9, -]+ Zbigniew Jędrzejewski[^\n]*?\s*\*\*\*\/\s*/\n\n/gms'
git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/\s+Copyright © [0-9, -]+ Zbigniew Jędrzejewski[^\n]*//gms'
2018-06-14 13:03:20 +02:00
Lennart Poettering 96b2fb93c5 tree-wide: beautify remaining copyright statements
Let's unify an beautify our remaining copyright statements, with a
unicode ©. This means our copyright statements are now always formatted
the same way. Yay.
2018-06-14 10:20:21 +02:00
Lennart Poettering 0c69794138 tree-wide: remove Lennart's copyright lines
These lines are generally out-of-date, incomplete and unnecessary. With
SPDX and git repository much more accurate and fine grained information
about licensing and authorship is available, hence let's drop the
per-file copyright notice. Of course, removing copyright lines of others
is problematic, hence this commit only removes my own lines and leaves
all others untouched. It might be nicer if sooner or later those could
go away too, making git the only and accurate source of authorship
information.
2018-06-14 10:20:20 +02:00
Lennart Poettering 810adae9e9 tree-wide: use proper unicode © instead of (C) where we can
Let's use a proper unicode copyright symbol where we can, it's prettier.

This important patch is very important.
2018-06-14 10:20:20 +02:00
Lennart Poettering 818bf54632 tree-wide: drop 'This file is part of systemd' blurb
This part of the copyright blurb stems from the GPL use recommendations:

https://www.gnu.org/licenses/gpl-howto.en.html

The concept appears to originate in times where version control was per
file, instead of per tree, and was a way to glue the files together.
Ultimately, we nowadays don't live in that world anymore, and this
information is entirely useless anyway, as people are very welcome to
copy these files into any projects they like, and they shouldn't have to
change bits that are part of our copyright header for that.

hence, let's just get rid of this old cruft, and shorten our codebase a
bit.
2018-06-14 10:20:20 +02:00
Iwan Timmer c9299be2f5 resolve: rename PrivateDNS to DNSOverTLS
PrivateDNS is not considered a good name for this option, so rename it to DNSOverTLS
2018-06-14 09:57:56 +02:00
Lennart Poettering ef31828d06 tree-wide: unify how we define bit mak enums
Let's always write "1 << 0", "1 << 1" and so on, except where we need
more than 31 flag bits, where we write "UINT64(1) << 0", and so on to force
64bit values.
2018-06-12 21:44:00 +02:00
Iwan Timmer d050561ac3 resolve: make PrivateDNS configurable per link
Like with DNSSec, make PrivateDNS configurable per link, so you can have trusted and untrusted links.
2018-06-11 21:35:58 +02:00
Zbigniew Jędrzejewski-Szmek bbac65bcc2
Merge pull request #9157 from poettering/unit-config-load-error
introduce a new "bad-setting" unit load state in order to improve "systemctl status" output when bad settings are used
2018-06-11 14:37:10 +02:00
Lennart Poettering c4555ad8f6 core: introduce a new load state "bad-setting"
Since bb28e68477 parsing failures of
certain unit file settings will result in load failures of units. This
introduces a new load state "bad-setting" that is entered in precisely
this case.

With this addition error messages on bad settings should be a lot more
explicit, as we don't have to show some generic "errno" error in that
case, but can explicitly say that a bad setting is at fault.

Internally this unit load state is entered as soon as any configuration
loader call returns ENOEXEC. Hence: config parser calls should return
ENOEXEC now for such essential unit file settings. Turns out, they
generally already do.

Fixes: #9107
2018-06-11 12:53:12 +02:00
Hiram van Paassen 06828bb617 networkd-link: add support to configure CAN interfaces
This patch adds support for kind "can". Fixes: #4042.
2018-06-09 15:12:31 +02:00
Zbigniew Jędrzejewski-Szmek 89278d96dc
Merge pull request #9221 from poettering/bus-track-destroy
add sd_bus_track and sd_event_source destroy callbacks too
2018-06-08 15:35:45 +02:00
Lennart Poettering ce3ec07f41
Merge pull request #9165 from ssahani/networkd-netdevsim
networkd: introduce netdev "Netdevsim" Driver
2018-06-07 16:56:32 +02:00
Lennart Poettering 15723a1db0 sd-event: add destroy callback logic to sd-event too
This adds what has been added to sd_bus_slot and sd_bus_track to
sd_event too.
2018-06-07 13:10:56 +02:00
Lennart Poettering 66223497d0 sd-bus: also add destroy callbacks to sd_bus_track objects
This augments previous work for this for sd_bus_slot objects, and adds
the same concept to sd_bus_track objects, too.
2018-06-07 13:10:56 +02:00
Zbigniew Jędrzejewski-Szmek fa17b4e8d9 bus: optionally call a callbacks for cleanup
This adds a function sd_bus_slot_set_destroy_callback() to set a function
which can free userdata or perform other cleanups.

sd_bus_slot_get_destory_callback() queries the callback, and is included
for completeness.

Without something like this, for floating asynchronous callbacks, which might
be called or not, depending on the sequence of events, it's hard to perform
resource cleanup. The alternative would be to always perform the cleanup from
the caller too, but that requires more coordination and keeping of some shared
state. It's nicer to keep the cleanup contained between the callback and the
function that requests the callback.
2018-06-06 23:01:57 +02:00
Lennart Poettering d08eb1fabd sd-event: use structure initialization instead of new0() where possible 2018-06-06 10:55:45 +02:00
Lennart Poettering 41e09d62c5 sd-event: add test for the new sd_event_add_inotify() API
This tests a couple of corner cases of the sd-event API including
changing priorities of existing event sources, as well as overflow
conditions of the inotify queue.
2018-06-06 10:53:56 +02:00
Lennart Poettering 97ef539169 sd-event: add new API for subscribing to inotify events
This adds a new call sd_event_add_inotify() which allows watching for
inotify events on specified paths.

sd-event will try to minimize the number of inotify fds allocated, and
will try to add file watches to the same inotify fd objects as far as
that's possible. Doing this kind of inotify object should optimize
behaviour in programs that watch a limited set of mostly independent
files as in most cases a single inotify object will suffice for watching
all files.

Traditionally, this kind of coalescing logic (i.e. that multiple event
sources are implemented on top of a single inotify object) was very hard
to do, as the inotify API had serious limitations: it only allowed
adding watches by path, and would implicitly merge watches installed on
the same node via different path, without letting the caller know about
whether such merging took place or not.

With the advent of O_PATH this issue can be dealt with to some point:
instead of adding a path to watch to an inotify object with
inotify_add_watch() right away, we can open the path with O_PATH first,
call fstat() on the fd, and check the .st_dev/.st_ino fields of that
against a list of watches we already have in place. If we find one we
know that the inotify_add_watch() will update the watch mask of the
existing watch, otherwise it will create a new watch. To make this
race-free we use inotify_add_watch() on the /proc/self/fd/ path of the
O_PATH fd, instead of the original path, so that we do the checking and
watch updating with guaranteed the same inode.

This approach let's us deal safely with inodes that may appear under
various different paths (due to symlinks, hardlinks, bind mounts, fs
namespaces). However it's not a perfect solution: currently the kernel
has no API for changing the watch mask of an existing watch -- unless
you have a path or fd to the original inode. This means we can "merge"
the watches of the same inode of multiple event sources correctly, but
we cannot "unmerge" it again correctly in many cases, as access to the
original inode might have been lost, due to renames, mount/unmount, or
deletions. We could in theory always keep open an O_PATH fd of the inode
to watch so that we can change the mask anytime we want, but this is
highly problematics, as it would consume too many fds (and in fact the
scarcity of fds is the reason why watch descriptors are a separate
concepts from fds) and would keep the backing mounts busy (wds do not
keep mounts busy, fds do). The current implemented approach to all this:
filter in userspace and accept that the watch mask on some inode might
be higher than necessary due to earlier installed event sources that
might have ceased to exist. This approach while ugly shouldn't be too
bad for most cases as the same inodes are probably wacthed for the same
masks in most implementations.

In order to implement priorities correctly a seperate inotify object is
allocated for each priority that is used. This way we get separate
per-priority event queues, of which we never dequeue more than a few
events at a time.

Fixes: #3982
2018-06-06 10:53:56 +02:00
Lennart Poettering cc59d29054 sd-event: voidify more things 2018-06-06 10:23:12 +02:00
Lennart Poettering 2a0dc6cd04 sd-event: propagate errors from source_set_pending() in all cases 2018-06-06 10:23:12 +02:00
Lennart Poettering ac989a783a sd-event: drop pending events when we turn off/on an event source 2018-06-06 10:23:12 +02:00
Lennart Poettering de05913d06 sd-event: use symbolic name for normal priority 2018-06-06 10:23:12 +02:00
Lennart Poettering a82f89aa9e sd-event: use structure initialization for epoll_event 2018-06-06 10:23:12 +02:00
Yu Watanabe 858d36c1ec path-util: introduce path_simplify()
The function is similar to path_kill_slashes() but also removes
initial './', trailing '/.', and '/./' in the path.
When the second argument of path_simplify() is false, then it
behaves as the same as path_kill_slashes(). Hence, this also
replaces path_kill_slashes() with path_simplify().
2018-06-03 23:39:26 +09:00
Susant Sahani 56e7fb5088 networkd: introduce netdev "Netdevsim" Driver
This "netdevsim" as implied by the name is a tool for network developers and is a simulator.
This simulated networking device is used for testing various networking APIs and at this time
is particularly focused on testing hardware offloading related interfaces.
2018-06-03 08:16:11 +05:30
Zbigniew Jędrzejewski-Szmek ea03f6ba0d sd-id128: return -ENOMEDIUM on null id
We currently return -ENOMEDIUM when /etc/machine-id is empty, and -EINVAL when
it is all zeros. But -EINVAL is also used for invalid args. The distinction
between empty and all-zero is not very important, let's use the same return
code.

Also document -ENOENT and -ENOMEDIUM since they can be a bit surprising.
2018-05-31 13:04:18 +02:00
Lennart Poettering 49f733c053
Merge pull request #9131 from poettering/memory-startswith
add new memory_startswith() helper and make use of it everywhere
2018-05-31 11:21:43 +02:00
Lennart Poettering fc2d4c89b8 sd-bus: make add match method callback slot "floating"
When we allocate an asynchronous match object we will allocate an
asynchronous bus call object to install the match server side.
Previously the call slot would be created as regular slot, i.e.
non-floating which meant installing the match even if it was itself
floating would result in a non-floating slot to be created internally,
which ultimately would mean the sd_bus object would be referenced by it,
and thus never be freed.

Let's fix that by making the match method callback floating in any case
as we have no interest in leaving the bus allocated beyond the match
slot.

Fixes: #8551
2018-05-30 17:34:34 +02:00
Lennart Poettering 7ae497b936 bus-slot: for bus slot objects with no explicit description use the match string as description
Let's make debugging a but easier with implicit descriptions for some
match objects.
2018-05-30 17:34:34 +02:00
Lennart Poettering 303acb7f2d sd-bus: add new sd_bus_slot_set_floating() call
This new call allows explicit control of the "floating" state of a bus
slot object. This is useful for creating a bus slot object first,
retaining a reference to it, using it for making changes to the slot
object (for example, set a description) and then handing it over to
sd-bus for lifecycle management.

It's also useful to fix #8551.
2018-05-30 17:13:51 +02:00
Lennart Poettering d27b725abf tree-wide: make use of memory_startswith() at various places 2018-05-30 13:11:51 +02:00
Zbigniew Jędrzejewski-Szmek 7a4b851229 sd-bus: use _cleanup_ more 2018-05-26 16:56:01 +02:00
Lennart Poettering 61d0578b07 add new portable service framework
This adds a small service "systemd-portabled" and a matching client
"portablectl", which implement the "portable service" concept.

The daemon implements the actual operations, is PolicyKit-enabled and is
activated on demand with exit-on-idle.

Both the daemon and the client are an optional build artifact, enabled
by default rhough.
2018-05-24 17:01:57 +02:00
Lennart Poettering 1a5a177eaf fileio: accept FILE* in addition to path in parse_env_file()
Most our other parsing functions do this, let's do this here too,
internally we accept that anyway. Also, the closely related
load_env_file() and load_env_file_pairs() also do this, so let's be
systematic.
2018-05-24 17:01:57 +02:00
Lennart Poettering 56b00d0028 tree-wide: remove some double newlines in headers, too 2018-05-22 16:13:45 +02:00
Lennart Poettering 4aab839c90 sd-resolve: tweak error assignment code a bit, use abs() and regular functions
Let's tweak the assignment of errors a bit, and automatically abs()
errnos, similar to how log_error_errno() and friends does it.

Macros are fine to use, but regular functions usually preferable if
there's no reason to use macros, because they avoid multiple evaluation
and suchlike. Hence, let's just use a regular funciton for assigning
errors, instead of macros.

Follow-up for #8993
2018-05-19 15:14:18 +02:00
Zbigniew Jędrzejewski-Szmek 38dad44332 sd-resolve: fix check for packet size
The protocol is that a string is serialized with the nul byte at the end, and
the terminator is included in length. We'd call strndup with offset 0, length
len1-1, and then a second time with offset len1, length len2-1, so in the end
the check was off by one. But let's require the terminating nul too, even if
we don't access it.

CID #1383035.
2018-05-15 12:31:42 +02:00
Zbigniew Jędrzejewski-Szmek 2da063370a sd-resolve: use structured initializers and _cleanup_
Also remove a break that cannot be reached and a resolve->dead check
that duplicates the loop condition.
2018-05-15 12:31:39 +02:00
Zbigniew Jędrzejewski-Szmek e8bce4fad3 sd-resolve: trivial indentation fixes 2018-05-15 12:27:02 +02:00
Zbigniew Jędrzejewski-Szmek f6ddae40ab sd-resolve: do not assert on packet size received over a socket
This is external data, even if trusted. We should not assert on it, but verify
and return proper error instead, which assert_return does. In particular,
write(2) says that a partial write could occur when interupted by a signal.
When compiled with asserts disabled, we could access memory outside of the
allocated buffer.

CID #1237671.
Follow-up for 1a96c8e1cc.
2018-05-15 12:25:44 +02:00
Zbigniew Jędrzejewski-Szmek 0b45ff5278 sd-resolve: add helper macro for setting of ret/_errno/_h_errno
Just to make things a bit shorter. This fixes an error where errno==-EIO would be set
(negative value), introduced in 1a96c8e1cc.
2018-05-14 17:22:22 +02:00
Zbigniew Jędrzejewski-Szmek dcd6361ea1 tree-wide: do not wrap assert_se in extra parentheses
We were inconsitently using them in some cases, but in majority not.
Using assignment in assert_se is very common, not an exception like in
'if', so let's drop the extra parens everywhere.
2018-05-14 17:22:22 +02:00
Yu Watanabe 1ab436e314 sd-bus: use free_and_strdup() 2018-05-14 14:09:03 +09:00
Lennart Poettering e4915c2797
Merge pull request #8953 from yuwata/bus-macro
core: simplify dbus properties
2018-05-10 22:51:17 -07:00
Yu Watanabe 945403e6ed path-util: introduce empty_to_root() and use it many places 2018-05-11 01:47:33 +09:00
David Tardon 2ab3a63549 sd-bus: use automatic cleanup more 2018-05-10 15:55:56 +02:00
Zbigniew Jędrzejewski-Szmek f5ce2e764f
Merge pull request #8689 from davide125/static
meson: add support for building static libsystemd and libudev
2018-05-10 00:39:36 +02:00
Yu Watanabe 130d3d22e9 tree-wide: use strv_free_and_replace() macro 2018-05-10 00:57:34 +09:00
Yu Watanabe 0f5bc6effd
Merge pull request #8938 from keszybz/sd-bus-automatic-cleanup
Use automatic cleanup more in sd-bus
2018-05-09 17:54:30 +09:00
David Tardon 33d8fe6057 use max. message size allowed by DBus spec (#8936)
C.f. https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-messages.
2018-05-09 10:33:28 +02:00
Zbigniew Jędrzejewski-Szmek 9df088f1ea sd-bus: add bus_freep and use _cleanup_ 2018-05-09 09:44:37 +02:00
Zbigniew Jędrzejewski-Szmek 01c4dcaffb sd-bus: use automatic cleanup more 2018-05-09 09:35:01 +02:00
Zbigniew Jędrzejewski-Szmek 0639f1354c sd-bus: trivial simplification 2018-05-09 09:30:58 +02:00
Davide Cavalca 70848ecfc6 meson: add support for building static libsystemd and libudev 2018-05-08 17:33:04 +02:00
Filipe Brandenburger a605e46f29 systemd-path: fix memory leak reported by ASAN (#8874)
The leak can be reproduced by running systemd-path --suffix .tmp under valgrind or asan:

    $ ./build/systemd-path --suffix .tmp search-binaries
    /usr/local/bin/.tmp:/usr/bin/.tmp:/usr/local/sbin/.tmp:/usr/sbin/.tmp:/home/vagrant/.local/bin/.tmp:/home/vagrant/bin/.tmp

    =================================================================
    ==19177==ERROR: LeakSanitizer: detected memory leaks

    Direct leak of 56 byte(s) in 1 object(s) allocated from:
        *0 0x7fd6adf72850 in malloc (/lib64/libasan.so.4+0xde850)
        *1 0x7fd6ad2b93d2 in malloc_multiply ../src/basic/alloc-util.h:69
        *2 0x7fd6ad2bafd2 in strv_split ../src/basic/strv.c:269
        *3 0x7fd6ad42ba67 in search_from_environment ../src/libsystemd/sd-path/sd-path.c:409
        *4 0x7fd6ad42bffe in get_search ../src/libsystemd/sd-path/sd-path.c:482
        *5 0x7fd6ad42c55b in sd_path_search ../src/libsystemd/sd-path/sd-path.c:607
        *6 0x7fd6ad42b3a2 in sd_path_home ../src/libsystemd/sd-path/sd-path.c:348
        *7 0x55f59c65ebea in print_home ../src/path/path.c:97
        *8 0x55f59c65f157 in main ../src/path/path.c:177
        *9 0x7fd6abaea009 in __libc_start_main (/lib64/libc.so.6+0x21009)

    Indirect leak of 68 byte(s) in 5 object(s) allocated from:
        *0 0x7fd6adf72850 in malloc (/lib64/libasan.so.4+0xde850)
        *1 0x7fd6abb5f689 in strndup (/lib64/libc.so.6+0x96689)

    Indirect leak of 25 byte(s) in 1 object(s) allocated from:
        *0 0x7fd6adf72850 in malloc (/lib64/libasan.so.4+0xde850)
        *1 0x7fd6abb5f689 in strndup (/lib64/libc.so.6+0x96689)
        *2 0x6c2e2f746e617266  (<unknown module>)

    SUMMARY: AddressSanitizer: 149 byte(s) leaked in 7 allocation(s).
2018-05-02 09:47:04 +03:00
Lennart Poettering da6053d0a7 tree-wide: be more careful with the type of array sizes
Previously we were a bit sloppy with the index and size types of arrays,
we'd regularly use unsigned. While I don't think this ever resulted in
real issues I think we should be more careful there and follow a
stricter regime: unless there's a strong reason not to use size_t for
array sizes and indexes, size_t it should be. Any allocations we do
ultimately will use size_t anyway, and converting forth and back between
unsigned and size_t will always be a source of problems.

Note that on 32bit machines "unsigned" and "size_t" are equivalent, and
on 64bit machines our arrays shouldn't grow that large anyway, and if
they do we have a problem, however that kind of overly large allocation
we have protections for usually, but for overflows we do not have that
so much, hence let's add it.

So yeah, it's a story of the current code being already "good enough",
but I think some extra type hygiene is better.

This patch tries to be comprehensive, but it probably isn't and I missed
a few cases. But I guess we can cover that later as we notice it. Among
smaller fixes, this changes:

1. strv_length()' return type becomes size_t

2. the unit file changes array size becomes size_t

3. DNS answer and query array sizes become size_t

Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=76745
2018-04-27 14:29:06 +02:00
Lennart Poettering 4e964aa05c networkd,udev: clean up MTU handling
This cleans up handling of MTU values across the codebase. Previously
MTU values where stored sometimes in uint32_t, sometimes in uint16_t,
sometimes unsigned and sometimes in size_t. This now unifies this to
uint32_t across the codebase, as that's what netlink spits out, and what
the majority was already using.

Also, all MTU parameters are now parsed with config_parse_mtu() and
config_parse_ipv6_mtu() is dropped as it is now unneeded.

(Note there is one exception for the MTU typing: in the DCHPv4 code we
continue to process the MTU as uint16_t value, as it is encoded like
that in the protocol, and it's probably better stay close to the
protocol there.)
2018-04-26 13:51:44 +02:00
Yu Watanabe 162c875513 bus-message: use streq_ptr() (#8786) 2018-04-23 10:13:26 +02:00
Lennart Poettering 2c75088094
Merge pull request #8615 from yuwata/fix-1329
timedated: support multiple NTP services
2018-04-19 16:22:50 +02:00
Lennart Poettering 5d13a15b1d tree-wide: drop spurious newlines (#8764)
Double newlines (i.e. one empty lines) are great to structure code. But
let's avoid triple newlines (i.e. two empty lines), quadruple newlines,
quintuple newlines, …, that's just spurious whitespace.

It's an easy way to drop 121 lines of code, and keeps the coding style
of our sources a bit tigther.
2018-04-19 12:13:23 +02:00
Lennart Poettering 2cb36f7c1e
Merge pull request #8575 from keszybz/non-absolute-paths
Do not require absolute paths in ExecStart and friends
2018-04-17 15:54:10 +02:00
Yu Watanabe 07411fd3bd timedate: move error mapping to bus-common-errors.[ch] 2018-04-17 14:03:25 +09:00
Zbigniew Jędrzejewski-Szmek e12d446b66 systemd-path: allow the default search path to be queried 2018-04-16 16:09:46 +02:00
Lennart Poettering 4d09e1c8ba
Merge pull request #8676 from keszybz/drop-license-boilerplate
Drop license boilerplate
2018-04-10 14:53:31 +02:00
Zbigniew Jędrzejewski-Szmek 30dd293c88 sd-event: use _cleanup_ to manage temporary references 2018-04-07 20:05:58 +02:00
Zbigniew Jędrzejewski-Szmek 11a1589223 tree-wide: drop license boilerplate
Files which are installed as-is (any .service and other unit files, .conf
files, .policy files, etc), are left as is. My assumption is that SPDX
identifiers are not yet that well known, so it's better to retain the
extended header to avoid any doubt.

I also kept any copyright lines. We can probably remove them, but it'd nice to
obtain explicit acks from all involved authors before doing that.
2018-04-06 18:58:55 +02:00
Yu Watanabe 1cc6c93a95 tree-wide: use TAKE_PTR() and TAKE_FD() macros 2018-04-05 14:26:26 +09:00
Zbigniew Jędrzejewski-Szmek 56fbd7187a sd-bus: allow description to be set for system/user busses (#8594)
sd_bus_open/sd_bus_open_system/sd_bus_open_user are convenient, but
don't allow the description to be set. After they return, the bus is
is already started, and sd_bus_set_description() fails with -EBUSY.
It would be possible to allow sd_bus_set_description() to update the
description "live", but messages are already emitted from sd_bus_open
functions, so it's better to allow the description to be set in
sd_bus_open/sd_bus_open_system/sd_bus_open_user.

Fixes message like:
Bus n/a: changing state UNSET → OPENING
2018-03-29 16:14:11 +02:00
Zbigniew Jędrzejewski-Szmek ffb3c2bd70
Merge pull request #8554 from poettering/chase-trail-slash
fs-util: add new CHASE_TRAIL_SLASH flag for chase_symlinks()
2018-03-26 18:00:08 +02:00
Lennart Poettering ae2a15bc14 macro: introduce TAKE_PTR() macro
This macro will read a pointer of any type, return it, and set the
pointer to NULL. This is useful as an explicit concept of passing
ownership of a memory area between pointers.

This takes inspiration from Rust:

https://doc.rust-lang.org/std/option/enum.Option.html#method.take

and was suggested by Alan Jenkins (@sourcejedi).

It drops ~160 lines of code from our codebase, which makes me like it.
Also, I think it clarifies passing of ownership, and thus helps
readability a bit (at least for the initiated who know the new macro)
2018-03-22 20:21:42 +01:00
Lennart Poettering d89e0dc81a sd-device: make use of the fact that log_debug_errno() returns the error passed in 2018-03-22 19:59:49 +01:00
Lennart Poettering 68b525d1d1 sd-bus: drop fd_nonblock() calls that are implied by rearrange_stdio() (#8514) 2018-03-21 11:46:49 +01:00
Lennart Poettering 5c24d63675
Merge pull request #8106 from dqminh/route-expires-kernel
move route expiration to kernel
2018-03-20 17:38:30 +01:00
Daniel Dao f02ba16389 setup route expiration in kernel if supported
kernel >= 4.5 (with commit 32bc201e19) supports
RTA_EXPIRES netlink attribute to set router lifetime. This simply detect
the kernel version (>=4.5) and set the lifetime properly, fallback to
expiring route in userspace for kernel that doesnt support it.

Signed-off-by: Daniel Dao <dqminh89@gmail.com>
2018-03-12 11:36:25 +00:00
Zbigniew Jędrzejewski-Szmek af7bce4165 fuzz: skip bus error map in bus_error_name_to_errno()
Fuzzing with AddressSanitizer reports an error here:
==11==ERROR: AddressSanitizer: global-buffer-overflow on address 0x7fe53f5497d8 at pc 0x7fe53ef055c9 bp 0x7ffd344e9380 sp 0x7ffd344e9378
READ of size 4 at 0x7fe53f5497d8 thread T0
SCARINESS: 27 (4-byte-read-global-buffer-overflow-far-from-bounds)
    #0 0x7fe53ef055c8 in bus_error_name_to_errno /work/build/../../src/systemd/src/libsystemd/sd-bus/bus-error.c:118:24
    #1 0x7fe53ef0577b in bus_error_setfv /work/build/../../src/systemd/src/libsystemd/sd-bus/bus-error.c:274:17
    #2 0x7fe53ef0595a in sd_bus_error_setf /work/build/../../src/systemd/src/libsystemd/sd-bus/bus-error.c:284:21
    #3 0x561059 in manager_load_unit_prepare /work/build/../../src/systemd/src/core/manager.c
    #4 0x560680 in manager_load_unit /work/build/../../src/systemd/src/core/manager.c:1773:13
    #5 0x5d49a6 in unit_add_dependency_by_name /work/build/../../src/systemd/src/core/unit.c:2882:13
    #6 0x538996 in config_parse_unit_deps /work/build/../../src/systemd/src/core/load-fragment.c:152:21
    #7 0x6db771 in next_assignment /work/build/../../src/systemd/src/shared/conf-parser.c:155:32
    #8 0x6d697e in parse_line /work/build/../../src/systemd/src/shared/conf-parser.c:273:16
    #9 0x6d5c48 in config_parse /work/build/../../src/systemd/src/shared/conf-parser.c:390:21
    #10 0x535678 in LLVMFuzzerTestOneInput /work/build/../../src/systemd/src/fuzz/fuzz-unit-file.c:41:16
    #11 0x73bd60 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /src/libfuzzer/FuzzerLoop.cpp:517:13
    #12 0x73a39f in fuzzer::Fuzzer::RunOne(unsigned char const*, unsigned long, bool, fuzzer::InputInfo*, bool*) /src/libfuzzer/FuzzerLoop.cpp:442:3
    #13 0x73d9bc in fuzzer::Fuzzer::MutateAndTestOne() /src/libfuzzer/FuzzerLoop.cpp:650:19
    #14 0x73fa05 in fuzzer::Fuzzer::Loop(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, fuzzer::fuzzer_allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) /src/libfuzzer/FuzzerLoop.cpp:773:5
    #15 0x71f75d in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/libfuzzer/FuzzerDriver.cpp:754:6
    #16 0x71285c in main /src/libfuzzer/FuzzerMain.cpp:20:10
    #17 0x7fe53da0482f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
    #18 0x430e68 in _start (/out/fuzz-unit-file+0x430e68)

0x7fe53f5497d8 is located 8 bytes to the right of global variable 'bus_common_errors' defined in '../../src/systemd/src/libsystemd/sd-bus/bus-common-errors.c:28:51' (0x7fe53f549300) of size 1232
SUMMARY: AddressSanitizer: global-buffer-overflow /work/build/../../src/systemd/src/libsystemd/sd-bus/bus-error.c:118:24 in bus_error_name_to_errno
Shadow bytes around the buggy address:
  0x0ffd27ea12a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ffd27ea12b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ffd27ea12c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ffd27ea12d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ffd27ea12e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0ffd27ea12f0: 00 00 00 00 00 00 00 00 00 00 f9[f9]f9 f9 f9 f9
  0x0ffd27ea1300: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
  0x0ffd27ea1310: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
  0x0ffd27ea1320: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ffd27ea1330: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ffd27ea1340: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==11==ABORTING

but I think it's a false positive because of our low-level magic in how this
area is constructed.
2018-03-11 16:33:59 +01:00
Evegeny Vereshchagin c8d980a3e9 tests: skip g_dbus_message_new_from_blob under asan
Some versions of asan report the following false positive
when strict_string_checks=1 is passed:

=================================================================
==3297==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f64e4090286 bp 0x7ffe46acd9a0 sp 0x7ffe46acd118 T0)
==3297==The signal is caused by a READ memory access.
==3297==Hint: address points to the zero page.
    #0 0x7f64e4090285 in __strlen_sse2 (/lib64/libc.so.6+0xaa285)
    #1 0x7f64e5a51e46  (/lib64/libasan.so.4+0x41e46)
    #2 0x7f64e4e5e3a0  (/lib64/libglib-2.0.so.0+0x383a0)
    #3 0x7f64e4e5e536 in g_dgettext (/lib64/libglib-2.0.so.0+0x38536)
    #4 0x7f64e48fac5f  (/lib64/libgio-2.0.so.0+0xc1c5f)
    #5 0x7f64e4c03978 in g_type_class_ref (/lib64/libgobject-2.0.so.0+0x30978)
    #6 0x7f64e4be9567 in g_object_new_with_properties (/lib64/libgobject-2.0.so.0+0x16567)
    #7 0x7f64e4be9fd0 in g_object_new (/lib64/libgobject-2.0.so.0+0x16fd0)
    #8 0x7f64e48fd43e in g_dbus_message_new_from_blob (/lib64/libgio-2.0.so.0+0xc443e)
    #9 0x564a6aa0de52 in main ../src/libsystemd/sd-bus/test-bus-marshal.c:228
    #10 0x7f64e4007009 in __libc_start_main (/lib64/libc.so.6+0x21009)
    #11 0x564a6aa0a569 in _start (/home/vagrant/systemd/build/test-bus-marshal+0x5569)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/lib64/libc.so.6+0xaa285) in __strlen_sse2
==3297==ABORTING

It's an external library and errors in external libraries are generally not very
useful for looking for internal bugs.

It would be better not to change the code and use standard suppression
techinques decribed at
https://clang.llvm.org/docs/AddressSanitizer.html#suppressing-reports-in-external-libraries,
but, unfortunaley, none of them seems to be able to suppress fatal errors in asan intself.
2018-03-09 15:17:03 +00:00
Yu Watanabe 280029d18f sd-bus: do not try to close already closed fd (#8392)
Fixes #8376, which is introduced by 2b33ab0957.
2018-03-08 14:19:35 +01:00
Lennart Poettering 6cc7e918ff
Merge pull request #8314 from poettering/rearrange-stdio
refactor how we rearrange fds for stdin/stdout/stderr
2018-03-02 15:42:03 +01:00
Lennart Poettering 62d74c78b5 coccinelle: add reallocarray() coccinelle script
Let's systematically make use of reallocarray() whereever we invoke
realloc() with a product of two values.
2018-03-02 12:39:07 +01:00
Lennart Poettering 40164c2ceb sd-bus: let's better not invade stdio territory when duplicating fds 2018-03-02 11:42:10 +01:00