Commit graph

5658 commits

Author SHA1 Message Date
Simon McVittie
074fbb0a83 doc: Use tar --xz to create dbus-docs.tar.xz
Signed-off-by: Simon McVittie <smcv@collabora.com>
Fixes: b805744029
2018-12-04 11:17:38 +00:00
Simon McVittie
28c27349e2 CI: Start supporting Debian 10 'buster', currently under development
This gives us a way to build on a more recent host OS if we want to.
For Gitlab-CI it's disabled by default.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-03 20:00:37 +00:00
Simon McVittie
0c553afcd9 CI: Stop building on Ubuntu 14.04 'trusty'
The version of gcc in trusty is too old for AddressSanitizer, which we
want to be able to start using, and Travis-CI finally supports Ubuntu
16.04 'xenial' now. This lets us remove some workarounds, but we need
to update others.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-03 20:00:32 +00:00
Simon McVittie
f9700a8a47 DBusHash: Program a bit more defensively
In particular, the assertions that bucket >= table->buckets and
bucket <= &table->buckets[table->n_buckets - 1] catch the bug fixed
by the previous commit, by ensuring that bucket is somewhere inside
the new array of buckets.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-03 19:05:13 +00:00
Simon McVittie
451192ba8a DBusHash: Recalculate bucket used if the table is rebuilt
Hash buckets are simply entries in an array owned by the hash table,
so every time the hash table's array of buckets is reallocated, we must
invalidate all pointers to buckets and recalculate them to point into
the new array of buckets. This was not always done. Luckily, we appear
to have avoided causing any actual memory corruption like this.

The only place where we reallocate the array of buckets is in
rebuild_table(), which is only called by add_allocated_entry(), which
is only called by add_entry(), which is only called by
find_generic_function() when create_if_not_found is true.
find_generic_function(), in turn, is only called by the
table->find_function() implementations.

The table->find_function() implementations have an optional "out"
parameter which returns a pointer to the hash bucket in which the returned
entry would be found. It is set in find_generic_function() for existing
entries, or in add_allocated_entry() if a new entry is created; after
that it is returned through callers unchanged until the caller of
table->find_function() is reached. The only callers that make use of the
"out" parameter in practice are _dbus_hash_iter_lookup(), to populate
a DBusHashIter, and the _dbus_hash_table_remove_TYPE() family, to pass
it to remove_entry().

We can ignore the _dbus_hash_table_remove_TYPE() family for two
reasons: they call the find function with create_if_not_found set to
FALSE, which never reallocates the hash table, and they do not store
the pointer to the bucket in the long-term. So we only need to consider
_dbus_hash_iter_lookup().

It is documented to be unsafe to add hash entries while a DBusHashIter
is open, and only adding a hash entry can trigger rebuild_table();
so we can assume that if _dbus_hash_iter_lookup() returns a valid
bucket, it remains valid forever.

The remaining case that must be considered is whether reallocation
can occur after setting the "out" parameter for the bucket, but before
returning it to _dbus_hash_iter_lookup(). We can see that it can: we
call rebuild_table() after recalculating the correct bucket. If we do,
and it actually causes a rebuild, then we must recalculate the bucket
accordingly.

Looking at the worst-case impact of this bug, if it is going to cause
any problem, it would only be when _dbus_hash_iter_lookup() is called
with create_if_not_found set true. This makes three uses of the bucket:
it stores it in the DBusHashTableIter, it calculates the next bucket
by finding the offset of the bucket in table->buckets and advancing
by one pointer, and it makes an assertion that should be tautologous,
enforcing that the next bucket corresponds to what it should.

When running under the AddressSanitizer, which makes allocations in
widely spaced regions of memory, on a 32-bit platform, we could (and
indeed do) find that the tautologous assertion fails. The current
bucket returned from the "out" parameter is a pointer into the old
value of table->buckets. If it's far enough before or after the new
table->buckets in the address space, then the offset in next_bucket
could overflow a 32-bit integer, resulting in the assertion no longer
being true.

The next commit will add extra assertions, which reproduce the bug
even without AddressSanitizer.

In production code without assertions, the impact is that
the ->bucket and ->next_bucket members of the DBusHashIter can be
invalid. They are used in _dbus_hash_iter_next() and
_dbus_hash_iter_remove_entry(). However, the only callers of
_dbus_hash_iter_lookup() outside test code are in bus/containers.c,
and neither calls either of those functions, so we dodge that bullet.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-03 19:03:55 +00:00
Simon McVittie
1191262f5e Translate Python-based tests to C
This simplifies bootstrapping: now you don't have to build dbus,
build dbus-python (with GLib), and use dbus-python to test dbus.

It also avoids test failures when using facilities like
AddressSanitizer. When libdbus is built with AddressSanitizer, but the
system copies of Python and dbus-python were not, dbus-python will exit
the Python interpreter on load, because libasan wasn't already
initialized. The simplest way to avoid this is to not use Python:
the scripts are not *that* hard to translate into C.

Both of these tests happen to be conditionally compiled for Unix only.
test_activation_forking() relies on code in TestSuiteForkingEchoService
that calls fork(), which can only work on Unix; meanwhile,
test_system_signals() tests the system bus configuration, which is
only relevant to Unix because we don't support using dbus-daemon as
a privilege boundary on Windows (and in any case D-Bus is not a Windows
OS feature, so the system bus cannot be used to communicate with OS
services like it can on most Linux systems).

This is also a partial solution to
<https://gitlab.freedesktop.org/dbus/dbus/issues/135>, by reducing the
size of name-test/.

For this to work, we need to build the test-service helper executable
even if embedded tests are disabled.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-03 17:42:48 +00:00
Simon McVittie
ebe5744375 test-service: Write diagnostics to stderr
When run by a TAP test, stdout is reserved for machine-readable
TAP output.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-03 17:42:48 +00:00
Simon McVittie
1dd31d32a0 Update NEWS
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-03 16:31:07 +00:00
Simon McVittie
152b09ff5a activation: Don't leak if delivering activation message is forbidden
This is technically a denial of service because the dbus-daemon will
run out of memory eventually, but it's a very slow and noisy one,
because all the rejected messages are also very likely to have
been logged to the system log.

Detected by AddressSanitizer.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Resolves: https://gitlab.freedesktop.org/dbus/dbus/issues/234
Reviewed-by: pwithnall
2018-12-03 16:28:13 +00:00
Simon McVittie
473f097471 Update NEWS
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-03 15:42:43 +00:00
Simon McVittie
017df70247 Merge branch 'max-conns-per-user' into 'master'
test/dbus-daemon: Mark max-connections-per-user as unimplemented on Windows

See merge request dbus/dbus!54

Reviewed-by: pwithnall
Reviewed-by: rhabacker
2018-12-03 15:30:57 +00:00
Simon McVittie
007de46c2a Merge branch '221-spec-fix' into 'master'
spec: Fix a typo in an ObjectManager example

Closes #221

See merge request dbus/dbus!56

Reviewed-by: smcv
2018-12-03 15:29:40 +00:00
Philip Withnall
f2e63e6c48 spec: Fix a typo in an ObjectManager example
As spotted by Peter Bigot.

Closes #221

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-12-03 11:39:11 +00:00
Ralf Habacker
19bc103e5d Enable check_get_connection_unix_process_id test on Windows with CMake
This check is now possible because with merge request
 https://gitlab.freedesktop.org/dbus/dbus/merge_requests/55
the prerequisites are valid.

It was already run if built with Autotools, because DBUS_WIN_FIXME
was only defined in the CMake build system.

[smcv: Add more context regarding Autotools vs. CMake]
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-03 11:31:22 +00:00
Simon McVittie
1b8efd9d44 Merge branch 'windows-pid' into 'master'
bus test: Accept GetConnectionUnixProcessID() success on Windows

See merge request dbus/dbus!55

Reviewed-by: pwithnall
2018-11-29 19:51:48 +00:00
Simon McVittie
5659784990 bus test: Accept GetConnectionUnixProcessID() success on Windows
Despite its name, which is a historical quirk, this is now a
generic cross-platform process ID on anything with the concept of
numbered processes. It appears it has actually worked on Windows
since dbus 1.7.x.

Bug: https://gitlab.freedesktop.org/dbus/dbus/issues/239
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-29 19:25:57 +00:00
Simon McVittie
89208de6a9 dbus-daemon(1): Document max_connections_per_user as Unix-only
The limit is accepted on Windows, but not enforced.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-29 18:17:46 +00:00
Simon McVittie
6e87d52a46 test/dbus-daemon: Mark max-connections-per-user as unimplemented on Windows
The implementation of the max-connections-per-user limit works in terms
of Unix uids, so it doesn't apply on Windows.

This is not a problem in practice, because it only makes sense to limit
connections per user if you have multiple users, and we don't support
the well-known system bus on Windows.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-29 14:24:52 +00:00
Simon McVittie
6d40ef8757 Merge branch 'dbus-daemon-inherited-fds' into 'master'
Don't let dbus-daemon and its subprocesses inherit unnecessary fds

See merge request dbus/dbus!50

Reviewed-by: rhabacker
Reviewed-by: pwithnall
2018-11-21 16:14:34 +00:00
Simon McVittie
06f467d689 Merge branch 'simplify-configure-checks' into 'master'
Simplify configure checks

See merge request dbus/dbus!10
2018-11-21 16:14:11 +00:00
Simon McVittie
94806fb2c7 Don't let dbus-daemon and its subprocesses inherit unnecessary fds
This should avoid test failures under CMake in which the
dbus-daemon inherits an unwanted fd from CMake's test framework, causing
the close-on-exec check before executing activated services to fail.

The dbus-daemon now marks all fds that it inherits, except for its
stdin, stdout and stderr, to be closed on exec. For completeness, the
dbus-daemons run by dbus-run-session and dbus-launch also now inherit
stdin, stdout, stderr and the pipes used to communicate with their
callers, but nothing else.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-20 19:09:18 +00:00
Simon McVittie
ebf487ef03 dbus-spawn-unix: If a fd is not close-on-exec, look it up in /proc/self/fd
In operating systems where /proc/self/fd works like it does on Linux
(Linux itself, and FreeBSD with Linux /proc emulation) this will give
us a clue about the fd that was leaked or opened incorrectly.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-20 18:56:26 +00:00
Simon McVittie
cdcf3c04dd FindDocBookXSL.cmake: Add
Taken from
<https://github.com/KDE/kdoctools/blob/master/cmake/FindDocBookXSL.cmake>

Signed-off-by: Simon McVittie <smcv@collabora.com>
Resolves: https://gitlab.freedesktop.org/dbus/dbus/issues/237
2018-11-20 18:29:39 +00:00
Simon McVittie
33bbf2c09d Merge branch '233-fix-broken-meinproc4' into 'master'
Fix broken meinproc4-based Docbook processing by using xsltproc instead

Closes #233

See merge request dbus/dbus!48

Reviewed-by: smcv
2018-11-20 17:13:31 +00:00
Ralf Habacker
a2aecf7d79 Add xsltproc usage to README.cmake 2018-11-20 15:57:21 +01:00
Ralf Habacker
06219344a8 Fix incorrect links in index html page used by cmake 2018-11-20 15:57:21 +01:00
Ralf Habacker
0764f08e7e Fix broken meinproc4 based docbook generating by already used xsltproc
Using xsltproc helps to reduce manual editing of xml doc and avoids
cyclic dependency (kdelibs depends on dbus and dbus depends on kdelibs).
It is available on all platforms (in the opposite to xmlto) and supports
freedesktop CI out of the box.

This commit adds docbook-xml and docbook-xsl as new dependency for cmake
and removes obsolate xmlto support, which depends on xsltproc.
2018-11-20 15:56:12 +01:00
Simon McVittie
2c765aafe8 Merge branch 'error-matches-bool' into 'master'
Add _DBUS_ASSERT_ERROR_XOR_BOOL, and a test for assertions

See merge request dbus/dbus!49

Reviewed-by: pwithnall
2018-11-20 13:53:56 +00:00
Simon McVittie
8c2eed45bd Merge branch 'desktop-file-leak-refactor' into 'master'
BusDesktopFile: Refactor logic to free the parser contents

See merge request dbus/dbus!43

Reviewed-by: pwithnall
2018-11-20 13:39:14 +00:00
Simon McVittie
c66552e1e0 Merge branch 'test-random-ints' into 'master'
marshal-recursive test: improve clarity, avoid undefined behaviour

See merge request dbus/dbus!46

Reviewed-by: pwithnall
2018-11-20 13:35:53 +00:00
Simon McVittie
a889e5aa8c Add a test for assertions
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-20 12:58:17 +00:00
Simon McVittie
77327b7bd8 _dbus_disable_crash_handling: Factor out from test-segfault
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-20 12:58:17 +00:00
Simon McVittie
16d2453ffa Improve diagnostics for error assertion failures
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-20 12:58:17 +00:00
Ralf Habacker
1acdf59619 Cleanup of cmake doc-related targets
There is now a top-level target "doc" that is always built.
Depending on the detected generators it depends on optional
targets like apidoc' and 'devhelp2'.
2018-11-20 13:56:39 +01:00
Simon McVittie
eef153e828 _DBUS_ASSERT_ERROR_XOR_BOOL: Add and use
As suggested by Philip Withnall in dbus!43.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-20 12:17:20 +00:00
Simon McVittie
3987f5a4bd BusDesktopFile: Refactor logic to free the parser contents
Now that we have _DBUS_STRING_INIT_INVALID, we can initialize
parser.data to a value that is safe for _dbus_string_free(), which
means we can put all the cleanup through a single code path that
definitely frees everything.

(This is just refactoring, not a correctness fix.)

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-20 12:01:12 +00:00
Ralf Habacker
bac2fd3aa4 ci-build.sh: Show file size in list of files to be able to compare generated file size 2018-11-20 12:59:23 +01:00
Simon McVittie
e1ad4e202d Update NEWS
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-20 11:32:54 +00:00
Simon McVittie
867c9bbe2e Merge branch 'va-copy' into 'master'
Don't check how to copy a va_list if we have va_copy; only use _DBUS_VA_COPY_ASSIGN on MSVC

See merge request dbus/dbus!35

Reviewed-by: rhabacker
2018-11-20 11:23:36 +00:00
Simon McVittie
e0f240e9e3 Merge branch 'containers-test-race' into 'master'
containers test: Wait a few more seconds for the socket to be deleted

See merge request dbus/dbus!47

Reviewed-by: pwithnall
2018-11-20 11:22:48 +00:00
Simon McVittie
2b229d0471 Merge branch 'keyring-undefined-shift' into 'master'
keyring: Avoid undefined out-of-range shift

See merge request dbus/dbus!45
2018-11-20 11:22:20 +00:00
Simon McVittie
269e0548e2 Merge branch 'desktop-file-leak' into 'master'
bus: Fix memory leaks when parsing .service files

See merge request dbus/dbus!42

Reviewed-by: pwithnall
2018-11-20 11:21:32 +00:00
Simon McVittie
04d9ee3437 Merge branch 'misc-leaks' into 'master'
Fix small memory leaks

See merge request dbus/dbus!41
2018-11-20 11:21:05 +00:00
Simon McVittie
c2ee90375a containers test: Wait a few more seconds for the socket to be deleted
Previously, we were waiting a few seconds for the dbus-daemon to stop
listening, then trying to connect again and asserting that it failed,
then immediately asserting that the socket had actually been deleted.
However, there is a race here: the dbus-daemon stops listening on the
socket, and then deletes it. If the test client wins the race by
probing to see whether the socket is present after the dbus-daemon
has stopped listening but before the dbus-daemon has deleted it, then
the test will fail.

This intermittently happens on Gitlab-CI, most recently in
<https://gitlab.freedesktop.org/smcv/dbus/-/jobs/45694>.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-19 13:53:52 +00:00
Simon McVittie
3241b4fe56 tests: Generate random values in unsigned integer space
When we're doing bitwise operations, addition with wraparound and
large left-shifts, it seems safer to use unsigned integers, where
the effect of overflow is well-defined (it wraps around). Signed
integer overflow is undefined behaviour, so compilers are free to
optimize by assuming that it cannot happen.

Detected by the undefined behaviour sanitizer (UBSan).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-19 12:28:25 +00:00
Simon McVittie
000ef530e8 tests: Remove unnecessary casts
If we have a variable "Type value;" then casting &value to (Type *) is
not useful, because it has that type already; it can only hide errors.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-19 12:28:25 +00:00
Simon McVittie
1f77c0a188 tests: Make it clearer that we avoid overflowing fixed-length buffers
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-19 12:28:22 +00:00
Simon McVittie
70fdc001be keyring: Avoid undefined out-of-range shift
Detected with UndefinedBehaviourSanitizer, which will warn on
about 50% of calls to this function, when s[3] is 128 or more,
because id is signed, so 128 << 24 is undefined signed overflow.

All we want here is a random non-negative signed int (in the range 0
to 2**31-1, with 31 bits varying). The intention seemed to be to
generate a random unsigned int, cast it to signed, and then negate it
if negative, but it seems simpler and more obviously correct to just
make sure the most  significant byte fits in the non-negative range.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-19 12:15:17 +00:00
Simon McVittie
2df063be18 BusDesktopFile: Don't leak content if key=value appears before [Section]
BusDesktopFile has a strange convention in which the various parser
helper functions (parse_section_start(), etc.) free the parser on error.
However, this particular error case happens outside the helper functions
and so will leak.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-19 11:38:11 +00:00
Simon McVittie
24d0be54cc desktop-file test: Don't leak errors
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-19 11:38:11 +00:00