Commit graph

1028 commits

Author SHA1 Message Date
Simon McVittie
2cc490f460 CI: Bump FreeBSD version to 14.2
FreeBSD 13.1 has been EOL since July 2023, but because there are
apparently no FreeBSD users among the dbus maintainers, nobody noticed.

dbus/dbus#308 is still present in FreeBSD 14.2, so remove the version
check when skipping that particular test.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2025-02-27 17:06:37 +00:00
Ralf Habacker
8a78585514 cmake: add missing environment variables for running tests
To achieve comparable results with Meson, the test environment should
provide the same set of environment variables when used in the source
code or the test environment.

Resolves: dbus/dbus#541

Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
2024-12-12 16:34:08 +01:00
Simon McVittie
648f4c2c37 cmake: Use a better bug reference
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-12-11 13:02:57 +00:00
Simon McVittie
229e48f549 bus: Update a build system cross-reference
We no longer have an Autotools build system, but Meson sets the same
environment variables that Autotools used to set. CMake does not, yet,
but ideally should.

Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/538
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-12-11 12:50:32 +00:00
Simon McVittie
3a37279e32 _dbus_check_fdleaks_leave: Try to describe what the leaked fd is
Similar to ebf487ef, but in a different situation.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-12-11 12:48:37 +00:00
Simon McVittie
7cbb7b75dd tests: Exercise NSS group lookup before running tests
Similar to #256, NSS plugins might open file descriptors the first time
they look up a system group, and leave them open. To avoid detecting
this as a leak, do one group lookup (which we expect to fail) before
starting testing, so that the fd is already open the first time we
call _dbus_check_fdleaks_enter(), and therefore is not considered to
have been leaked in _dbus_check_fdleaks_leave().

Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/540
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-12-10 14:57:13 +00:00
Simon McVittie
cd667b9556 build: Allow version number to be followed by "-" and a suffix
Some distributions are known to have shipped dbus 1.15.x as though it
was a stable release, and it isn't clear whether they knew that we use
the odd/even versioning convention like GLib does.

If we add a -alpha, -beta, -rc suffix to development versions starting
from 1.17.0, then distros that know we use odd/even versioning will
know that our development versions are not a stable-branch, and so will
distros that mistakenly think we use the "semantic versioning"
versioning convention popularized by <https://semver.org/>.

(We intentionally do not use semver, because semver would require us to
ship a new minor version every time we add new API, and we do not have
the resources to provide security support for an unlimited number of
minor versions in parallel: we need to be able to nominate a subset of
our releases as having longer-term security support, in a way that signals
to distros that these are the releases they should prefer to ship.)

CMake's `project()` doesn't allow this version number format[1], but
we intend to use version numbers where the (major, minor, micro) tuple
is enough to uniquely identify a release, so we can just tell CMake our
version number without the suffix and there will be no ambiguity.

Similarly, the dash is not allowed in GNU ld version scripts, so use
the form of the version number without the suffix there.

[1] https://gitlab.kitware.com/cmake/cmake/-/issues/16716

Helps: dbus#530
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-12-10 12:30:16 +00:00
Simon McVittie
9c5b5838f5 Rename "embedded tests" to "intrusive tests"
This hopefully helps to get across the point that enabling these tests
adds instrumentation to libdbus and dbus-daemon, with a potentially
significant impact on code size, performance and security.

To avoid a huge diffstat which would be difficult to review, the cpp
macro that is checked by most of the C code is still
DBUS_ENABLE_EMBEDDED_TESTS, which is defined or undefined under exactly
the same conditions as the new DBUS_ENABLE_INTRUSIVE_TESTS.

Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/537
Co-authored-by: Philip Withnall <philip@tecnocode.co.uk>
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-12-10 10:25:23 +00:00
Alan Coopersmith
66170cbb21 test: fix cleanup_test_socket_tempdir on Solaris
Solaris does not allow rmdir() to remove the cwd, so chdir() out of
the tempdir before removing it.

Without this fix, misc-internal reported a failure on Solaris 11.4:
not ok 16 - failed to remove test socket directory /tmp/dbus-test-tduvWc

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2024-10-18 14:16:26 +00:00
Alan Coopersmith
72642d7ff6 test: Move fd limit check into test_flood
Other tests have different requirements for fds (and already check for
them), so move this check into the specific test (mirroring what those
other tests already do) instead of blocking the whole test program,
incorrectly using autoconf test return codes instead of TAP protocol,
as discussed in #176.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2024-10-13 12:37:32 -07:00
Alan Coopersmith
f851484bf5 test: raise fd limit to maximum before running fdpass tests
Many of these tests require more than the default fd limit on some systems,
so raise the limit, if we can, to give them a better chance of being able
to run.

Closes #176
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2024-10-13 12:26:48 -07:00
Simon McVittie
e01e03cf97 build: test/name-test/run-test.sh needs dbus-launch
If we're building on Unix with the message bus and tools enabled, then
we need to compile dbus-launch before we can expect this test to pass.

Continuation of commit 55e60abe "test: add missing test dependencies".

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-10-01 11:59:52 +00:00
Simon McVittie
c2930ddf82 test: Always initialize an "out" parameter
check_valid_fd() does not touch its second parameter if the fd is not,
in fact, a valid fd. Initialize the "out" parameter to the opposite
of the value we are hoping for, so that both assertions will fail if
there is a problem.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-09-25 14:42:15 +01:00
Alyssa Ross
55e60abe18 test: add missing test dependencies
This fixes doing "meson setup" followed by "meson test", without doing
a full build in between.

Signed-off-by: Alyssa Ross <hi@alyssa.is>
2024-07-29 14:09:37 +00:00
Alyssa Ross
3f988b9fb3
test: use "tty" group rather than "bin"
Unlike "bin", "tty" actually means something on modern Linux distros,
and is used by a default udev rule, so it's more likely to exist on
distros than a group that just exists for historical compatibility
with who knows what.

"tty" exists on macOS, Debian, and Fedora (the criteria used for
choosing "bin" in f2905def ("policy tests: Use bin rather than
nogroup, wheel, or root")), but also fixes running the bus test for me
on NixOS, which has "tty" but not "bin".

Closes: https://gitlab.freedesktop.org/dbus/dbus/-/issues/514
Signed-off-by: Alyssa Ross <hi@alyssa.is>
2024-07-28 12:50:37 +02:00
Simon McVittie
e159f1f406 sysdeps: Remove _dbus_string_append_int()
It's a wrapper around snprintf(), so we are not gaining any efficiency
versus _dbus_string_append_printf(), and might as well use the more
general function instead. Doing it this way might even be a little *more*
efficient, since it reduces reallocations; it's certainly more concise.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-18 12:19:16 +00:00
Ralf Habacker
8ea959b24e Remove autotools related files 2023-09-01 14:05:08 +00:00
Alexander Kanavin
4c658af0b8 time: use dbus_int64_t for seconds instead of long
On 32 bit systems long will overflow in 2038, causing complete breakage.
This is confirmed by running dbus's test suite on a 32 bit system
with system time set to 2040 (and configured to use 64 bit time_t of course).

Note that both timespec and timeval are specified with time_t for the
seconds component. This should propagate everywhere where that data is
passed and stored, but previously _dbus_get_monotonic_time() and
_dbus_get_monotonic_time() would truncate it to long.

Also add a function for parsing dbus_int64_t from
files, as existing functions can only handle long.

Signed-off-by: Alexander Kanavin <alex@linutronix.de>
2023-08-23 14:42:05 +02:00
Simon McVittie
9bac14973d test: Add a targeted test for _dbus_unix_groups_from_uid()
Helps: https://gitlab.freedesktop.org/dbus/dbus/-/issues/343
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-18 18:51:08 +01:00
Simon McVittie
980e52898b userdb: Add proper error reporting when getting groups from a uid
Previously, if dbus_connection_get_unix_user() succeeded but
_dbus_unix_groups_from_uid() failed, then bus_connection_get_unix_groups()
would incorrectly fail without setting the error indicator, resulting
in "(null)" being logged, which is rather unhelpful.

This also lets us distinguish between ENOMEM and other errors, such as
the uid not existing in the system's user database.

Fixes: 145fb99b (untitled refactoring commit, 2006-12-12)
Helps: https://gitlab.freedesktop.org/dbus/dbus/-/issues/343
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-18 16:04:03 +01:00
Simon McVittie
b54af72dfd Add REUSE copyright/license information for binary message blobs
Most of these binary blobs is mechanically derived from the
corresponding .hex file, which is hand-written.

boolean-has-no-value.message-raw is presumably either hand-constructed
or fuzzer-generated: it was committed by a Red Hat employee and never
altered, so I've assumed Red Hat is the copyright holder. Permission
was already granted by Red Hat to relicense their dbus contributions
under the MIT (Expat) license.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-15 15:41:17 +01:00
Simon McVittie
3190b488e3 Add SPDX license tags for the MIT (Expat) license, where straightforward
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-14 17:18:04 +00:00
Luca Boccassi
80d523dcc8 DBusCredentials: add support for PID FDs via SO_PEERPIDFD
The new socket option SO_PEERPIDFD allows to pin the process on the
other side of the socket by file descriptor, which closes a race
condition where a PID can be reused before we can pin it manually.
Available since Linux v6.5.

When storing credentials, pin the process by FD from the PID.
When querying the PID, if the PID FD is available, resolve
it from there first if possible.

Ensure the DBusCredentials object only returns the PID FD if it was
obtained by this call, so that we know for sure we can rely on it
being safe against PID reuse attacks.

Signed-off-by: Luca Boccassi <bluca@debian.org>
2023-08-08 12:24:20 +01:00
Simon McVittie
986611ad0f monitor test: Reproduce dbus/dbus#457
The exact failure mode reported in dbus/dbus#457 is quite difficult
to achieve in a reliable way in a unit test, because we'd have to send
enough messages to a client to fill up its queue, then stop that client
from draining its queue, while still triggering a message that gets a
reply from the bus driver. However, we can trigger the same crash in a
slightly different way by not allowing the client to receive a
particular message. I chose NameAcquired.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-06-06 12:01:02 +01:00
Simon McVittie
8ee5d3e044 monitor test: Log the messages that we monitored
This is helpful while debugging test failures.

Helps: dbus/dbus#457
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-06-06 12:01:02 +01:00
Ralf Habacker
8189a74c6c Add test for _dbus_string_skip_blank()
[smcv: Fix a memory leak]

Reproduces: https://gitlab.freedesktop.org/dbus/dbus/-/issues/421
2023-02-08 12:03:19 +00:00
Daniel Wagner
b1e8793e8d gitlab-ci: build libdbus as subproject
Test it's possible to consume libdbus as a subproject.

Suggested-by: Simon McVittie <smcv@collabora.com>
Signed-off-by: Daniel Wagner <dwagner@suse.de>
2023-02-07 09:07:32 +01:00
Ralf Habacker
57ab4c7a48 cmake: add missing test for header-fields
Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
2023-02-06 13:43:59 +00:00
Ralf Habacker
20febb522b Add multithreaded unit test for DBusCounter to available build systems
The mentioned test is build on unix like platforms when embedded tests
are enabled.
2023-01-05 16:43:55 +01:00
Daniel Wagner
afb5bbaba4 meson: Introduce message_bus and tools command line option
To make the consume libdbus via Meson's subproject use case more useful,
introduce message_bus and tools command line options which control if
the D-Bus daemon and/or the tools are build. The idea here is that
depending projects are interested only in the library.

The strong recommendation is only to build libdbus as static library:

  libdbus_dep = dependency(
    'dbus-1',
    required: get_option('libdbus'),
    fallback: ['dbus', 'libdbus_dep'],
    default_options: [
      'default_library=static',
      'embedded_tests=false',
      'message_bus=false',
      'modular_tests=disabled',
      'tools=false',
    ],
  )

This ensures that any installed D-Bus infrastructure on the target
system is not overwritten.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
2023-01-04 09:35:06 +01:00
Ralf Habacker
2dee523608 Add SPDX license marker for the AFL-2.1 OR GPL-2.0-or-later license
The full license texts are not added because they were already
added in a previous commit.

Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>

see #394
2023-01-04 07:53:44 +00:00
Dave Jones
9950464761 Permit access to /tmp dbus socket
After 6e48c317 the test-apparmor-activation test fails as it can no
longer access the dbus socket in /tmp. This commit updates the apparmor
profile used within the test
2023-01-03 18:42:51 +00:00
Simon McVittie
a7e4bac015 Fix some stray filename references for GPL-2.0-or-later
The SPDX name for this license includes the `.0`.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-11-29 20:43:01 +00:00
Simon McVittie
54b56ab875 Use 'continue' keyword in preference to 'goto' where possible
In some more complicated loops, we do need to use 'goto' to exit from
an inner loop, or to jump to cleanup or an increment of an iterator
immediately before the next loop iteration. However, in these simple
cases, jumping to a label immediately before the 'while' keyword is
unnecessary: we can use an equivalent 'continue' statement for flow
control.

This makes it easier for maintainers to notice the loops where we are
doing something more complicated, which still use 'goto', and know
that they need to pay more attention in those cases.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-11-29 18:50:06 +00:00
Simon McVittie
eae69d2c1a dbus-hash: Add (AFL-2.1 OR GPL-2.0-or-later) AND TCL SPDX license identifier
The TCL-derived code is under its own license, so the overall license
of the file is (AFL-2.1 OR GPL-2.0-or-later) AND TCL.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-11-29 13:33:53 +00:00
Simon McVittie
4aa7052c6f test-exit: Add a permissive license
Red Hat have previously given permission for relicensing, and all
subsequent contributions to this file were trivial.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-12 12:08:38 +00:00
Simon McVittie
fb1460ee32 test-threads-init: Add a permissive license
With permission from Philip Withnall on behalf of Endless, me on behalf
of Collabora, and relying on previous permission from Red Hat
representatives.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-12 12:08:38 +00:00
Simon McVittie
2e705c9b49 manual-tcp: Add a permissive license
With permission from Ralf Habacker via dbus!304 and the mailing list.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-12 12:08:38 +00:00
Simon McVittie
31a2624796 manual-paths: Apply a permissive license
This was contributed by Ralf Habacker and later edited by me, with a
trivial change from Thomas Zimmermann which I don't think affects its
copyright.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-12 12:08:38 +00:00
Simon McVittie
82b3c6b7dd manual-dir-iter: Apply a permissive license
This was contributed by Ralf Habacker, with a trivial change from
Philip Withnall which I don't think affects its copyright.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-12 12:08:38 +00:00
Simon McVittie
ada440c5ba test-shutdown: Apply a permissive license
All significant contributions to this file were from companies or
individuals that gave permission for relicensing to MIT (I have assumed
that trivial changes from Marcus Brinkmann and Kjartan Maraas were too
small to affect copyright status).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-12 12:08:38 +00:00
Simon McVittie
812a690d62 test-ids: Apply a permissive license
All significant contributions to this file were from companies that gave
permission for relicensing to MIT (I have assumed that trivial changes
from Marcus Brinkmann and Ralf Habacker were too small to affect
copyright status).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-12 12:08:38 +00:00
Simon McVittie
21763bfd41 test-autolaunch: Add a permissive license
The license for this file was never stated, but all contributions to it
have been from Red Hat or Collabora, and representatives of both
companies gave permission for MIT relicensing in 2007.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-12 12:08:38 +00:00
Simon McVittie
fdd589c8d8 launch-helper-for-tests: Add a permissive license
I wrote this, and it hasn't changed since.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-12 12:08:38 +00:00
Ralf Habacker
7724bf574c test-autolaunch-win.c: Prevent assertion in dbus_message_unref()
dbus_message_unref() is in principle able to handle a NULL parameter, but
causes the program to abort when `fatal_warnings_on_check_failed` is set.

Therefore the call with a NULL parameter is avoided from now on.

Fixes #422
2022-10-12 09:38:46 +02:00
Simon McVittie
f325252e5e test-autolaunch-win: Remove redundant check for ERROR message
This seems to have been intended to give a more specific error message
if the method call failed, but it will not have been effective, because
dbus_connection_send_with_reply_and_block() ends with a check for ERROR
messages using dbus_set_error_from_message(). This means that if the
reply was an ERROR message, it will already have been converted into a
DBusError by the time call_method() regains control.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-11 18:20:53 +00:00
Simon McVittie
a7bbff5baf test-autolaunch-win: Don't overwrite an error with another error
An unrelated branch failed CI with this assertion failure:

    26: dbus[6768]: error: arguments to dbus_set_error() were incorrect,
    assertion "(error) == NULL || !dbus_error_is_set ((error))" failed in
    file ...\dbus-errors.c line 365.

Looking at the test, this seems to be the most likely candidate for
this bug in error handling, which is masking whatever the real cause
for the failure was (we can't tell from here). If
dbus_connection_send_with_reply_and_block() returns NULL, then it should
already have set the error.

Fixing this bug in the error handling will hopefully give us a better
error message for the actual failure if it happens again.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-11 18:20:53 +00:00
Ralf Habacker
4712a05874 dbus/dbus-macros-internal, test/test-platform-mutex.c: Use upper case for SPDX license operator
https://spdx.github.io/spdx-spec/SPDX-license-expressions/ says that
using upper-case operators is canonical.
2022-10-11 13:00:00 +00:00
Simon McVittie
3c0e63c10a dbus-message: Report OOM as OOM, not InvalidArgs
Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/420
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-11 11:54:21 +00:00
Kai A. Hiller
bc23b03b5c dbus-connection: Test built-in filters 2022-10-11 10:50:08 +00:00