Commit graph

5577 commits

Author SHA1 Message Date
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
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
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
Simon McVittie
85d07a97e6 bus_container_instance_new: Don't leak empty DBusString object
We already stole its data, but that allocated a new buffer, which we
still need to free.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-19 11:35:22 +00:00
Simon McVittie
5accf42aab bus_driver_handle_become_monitor: Don't leak zero-length array of rules
Only privileged users can trigger this leak, so it is not a denial of
service attack.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-19 11:35:22 +00:00
Simon McVittie
f33038bc1b build: Require va_copy() or __va_copy() on non-MSVC compilers
va_copy() is a C99 feature, and should be widely supported by now.
gcc in strict C89 mode implements an equivalent __va_copy() instead.

MSVC 2013 implements va_copy(), but at the moment we still aim to support
MSVC 2010 and 2012, which don't have it. However, we know that in
Windows ABIs, va_list is a pointer, so we can use
_DBUS_VA_COPY_ASSIGN. We do not support MSVC for Autotools builds, only
CMake, due to its non-Unixish command-line interface.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-19 11:27:25 +00:00
Simon McVittie
dab4a12e0e CI: Do one build with mingw + CMake by default
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-19 11:27:25 +00:00
Simon McVittie
38e4d72fdc Only use _DBUS_VA_COPY_ASSIGN to implement va_copy() on MSVC
We don't know that _DBUS_VA_COPY_ASSIGN is always the right choice.
However, we do know that it's OK on MSVC versions too old to support
va_copy().

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-19 11:27:25 +00:00
Simon McVittie
6278951f6d Don't check how to copy a va_list if we already have va_copy()
If we already have ISO C va_copy() or its non-standard counterpart
__va_copy(), then there's no need to do an AC_RUN_IFELSE or its
CMake equivalent to detect whether "args2 = args1" or "*args2 = *args1"
works. AC_RUN_IFELSE is problematic during cross-compilation, where the
program cannot be run (you have to know in advance that the test program
will be run and what its result will be), so we want to avoid it whenever
possible.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-19 11:27:25 +00:00
Simon McVittie
c018e0b1b2 Merge branch 'cmake-generate-dbus.devhelp2' into 'master'
Add generating dbus.devhelp2 to cmake build system

See merge request dbus/dbus!39
2018-11-19 11:06:36 +00:00
Ralf Habacker
ca20822d19 Add generating dbus.devhelp2 to cmake build system 2018-11-16 23:01:56 +01:00
Simon McVittie
2908a4da6a embedded tests: Make it easier to run a single test-case
When running tests under "make check" or similar to take advantage
of facilities like AM_TESTS_ENVIRONMENT and AX_VALGRIND_CHECK, it's
more straightforward to set an environment variable than to pass a
command-line option.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://gitlab.freedesktop.org/dbus/dbus/issues/218
2018-11-16 15:16:21 +00:00
Simon McVittie
dd4fb66f67 Update NEWS
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-16 15:04:52 +00:00
Simon McVittie
dde5844c59 Merge branch 'iso-varargs' into 'master'
internals: Assume compiler supports a subset of ISO varargs syntax

See merge request dbus/dbus!36

Reviewed-by: rhabacker
Reviewed-by: pwithnall
2018-11-16 11:41:32 +00:00
Simon McVittie
f93b63587f internals: Assume compiler supports a subset of ISO varargs syntax
We have considerable anecdotal evidence that every relevant compiler
supports at least the small part of ISO varargs syntax that we need
here, because tools/tool-common.h has contained

    #define VERBOSE(...) do {} while (0)

since dbus 1.9.2 (2014) and nobody has complained yet. With that in
mind, let's simplify.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-15 18:55:57 +00:00
Simon McVittie
a6674bff17 Merge branch 'dbus-va-copy-fixup' into 'master'
Refactor cmake checks for DBUS_VA_COPY and DBUS_VA_COPY_ARRAY

See merge request dbus/dbus!29
2018-11-15 15:40:32 +00:00
Ralf Habacker
a0503f0c99 Refactor cmake checks for DBUS_VA_COPY and DBUS_VA_COPY_ARRAY
For test case execution, CheckCSourceCompiles is now used instead
of try_compile and the determination of DBUS_VA_AS_ARRAY is
performed with a separate test instead of evaluating the result
of HAVE_VA_COPY and HAVE___VA_COPY.

The tests are performed for all supported compilers. Since older
MSVC compilers (< 2013) do not support va_copy(), the macro
_DBUS_VA_ASSIGN(a1,a2) with the implementation { a1 = a2; } is used
as a fallback.
2018-11-15 15:18:22 +00:00
Simon McVittie
0732d3ee1b Merge branch 'avc_open' into 'master'
Stop using avc_init() which is deprecated and use avc_open() instead. Also, use SELINUX_CB_POLICYLOAD instead of AVC_CALLBACK_RESET callback.

See merge request dbus/dbus!31

Reviewed-by: smcv
2018-11-15 15:17:47 +00:00
Laurent Bigonville
a442601cb2 Use SELINUX_CB_POLICYLOAD instead of AVC_CALLBACK_RESET callback
Use SELINUX_CB_POLICYLOAD instead of AVC_CALLBACK_RESET callback as this
only seems necessary on policy reload and not if the enforcing mode is
changing.

See discussion at https://marc.info/?l=selinux&m=152173501930182&w=2

https://gitlab.freedesktop.org/dbus/dbus/issues/134
2018-11-15 15:59:49 +01:00
Laurent Bigonville
67f7bdf8c2 Stop using avc_init() which is deprecated
Stop using avc_init() and use avc_open() instead. With this commit
dbus-daemon will stop using a thread to monitor the avc netlink and will
poll it instead.

https://gitlab.freedesktop.org/dbus/dbus/issues/134
2018-11-15 15:59:49 +01:00
Simon McVittie
3525335f76 Merge branch 'pc-file-trailing-slash-issue' into 'master'
Avoid double slashes in paths created by pkg-config

See merge request dbus/dbus!30
2018-11-15 13:39:31 +00:00
Ralf Habacker
696a6b629d Avoid double slashes in paths created by pkg-config
If in a .pc variable a path is created from another
variable, such as exec_prefix=${prefix}/lib, prefix
must not contain a trailing slash to avoid double
slashes in the generated path.
2018-11-15 13:12:48 +00:00
Simon McVittie
9983744326 Merge branch 'msvc-compile-fix' into 'master'
Msvc compile fix

See merge request dbus/dbus!33

Reviewed-by: smcv
Reviewed-by: pwithnall
2018-11-15 13:09:54 +00:00
Ralf Habacker
59332d06d7 Windows MSVC compile fix
Do not use unistd.h with MSVC because this header file does not
exist for this compiler.

Fixup of commit b0c0652005
2018-11-08 14:20:55 +01:00
Simon McVittie
59013d4c43 Merge branch '222-comm-whitespace' into 'master'
Fix whitespace and error behaviour for _dbus_command_from_pid()

Closes #222

See merge request dbus/dbus!28

Reviewed-by: pwithnall
2018-11-01 12:07:22 +00:00
Simon McVittie
e8cdb9171e tests: Assert that _dbus_command_for_pid() has correct error behaviour
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-10-31 16:56:36 +00:00
Simon McVittie
47fc3ed2a9 sysdeps: Return an error for _dbus_command_for_pid on Windows
If a function returns boolean for success/error, and returns a
DBusError, then it should set the DBusError if and only if it
returns FALSE.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-10-31 16:56:36 +00:00
Simon McVittie
d70040d8d2 tests: Assert that dbus#222 has been fixed 2018-10-31 16:56:36 +00:00
Simon McVittie
f7bf69443d sysdeps: Remove trailing NUL from command lines from /proc
Resolves: https://gitlab.freedesktop.org/dbus/dbus/issues/222
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-10-31 16:56:36 +00:00
Simon McVittie
93c1d08300 tests: Add a unit test for _dbus_command_for_pid()
In particular this demonstrates that dbus#222 has been solved.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-10-31 16:56:36 +00:00
Simon McVittie
6eb1c2cd53 test_get_helper_executable: Add function
This is basically the same as get_test_exec() in dbus-spawn-test.c,
but GLib-flavoured.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-10-31 16:56:36 +00:00
Simon McVittie
2a2c6e6790 test_incomplete: Add function
This is a wrapper for g_test_incomplete(), which works around bugs in
that function prior to GLib 2.57.3. I originally wrote it for librsvg.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-10-31 16:56:36 +00:00