Commit graph

5191 commits

Author SHA1 Message Date
Simon McVittie
173f694b91 test_peer_ping: Don't leak one method call per invocation
Previously, we allocated m both during initialization, and after
deciding not to skip this test.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103600
2017-11-24 12:18:45 +00:00
Simon McVittie
f058394a0e _dbus_server_new_for_tcp_socket: Simplify error unwinding
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89104
2017-11-24 12:17:38 +00:00
Simon McVittie
3507b4fc12 _dbus_server_new_for_socket: Simplify error unwinding
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89104
2017-11-24 12:17:37 +00:00
Simon McVittie
ac6c4d384d Add a targeted test for OOM during _dbus_server_new_for_tcp_socket()
This also covers _dbus_server_new_for_socket(), which is one of the
worse places in terms of complexity of the error-unwinding path
(3 labels).

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89104
2017-11-24 12:17:35 +00:00
Simon McVittie
a9aef9b378 dbus-nonce: Don't crash on encountering OOM
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89104
2017-11-24 12:17:33 +00:00
Simon McVittie
9ded6907e6 _dbus_listen_tcp_socket: Don't rely on dbus_realloc setting errno
dbus_realloc() doesn't guarantee to set errno (if it did, the
only reasonable thing it could set it to would be ENOMEM). In
particular, faking OOM conditions doesn't set it. This can cause an
assertion failure when OOM tests assert that the only error that can
validly occur is DBUS_ERROR_NO_MEMORY.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89104
2017-11-24 12:17:32 +00:00
Simon McVittie
d48d31cc21 _dbus_server_new_for_tcp_socket: Don't pile up errors on OOM
If _dbus_noncefile_create() has failed and set error, it is incorrect
for us to set it again.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89104
2017-11-24 12:17:30 +00:00
Simon McVittie
1ecaff10da _dbus_server_new_for_launchd: Don't leak fd on failure
If _dbus_server_new_for_socket() fails, it is the caller's
responsibility to close the fds. All other callers did this.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89104
2017-11-24 12:17:29 +00:00
Simon McVittie
0c03b505a9 _dbus_server_new_for_socket: Properly disconnect during error unwinding
_dbus_server_finalize_base() asserts that the socket has been
disconnected, but in some OOM code paths we would call it without
officially disconnecting. Do so.

This means we need to be a bit more careful about what is
socket_disconnect()'s responsibility to clean up, what is
_dbus_server_new_for_socket()'s responsibility, and what is the caller's
responsibility.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89104
2017-11-24 12:17:26 +00:00
Simon McVittie
1ce34beef8 _dbus_server_new_for_socket: Invalidate watches during error unwinding
We assert that every watch is invalidated before it is freed, but
in some OOM code paths this didn't happen.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89104
2017-11-24 12:17:24 +00:00
Simon McVittie
fa123560d3 _dbus_transport_new_for_socket: Simplify with _DBUS_STRING_INIT_INVALID
This is one of the few places that has test coverage for all the OOM
code paths. It was also one of the worst (most complicated)
error-unwinding locations, with labels failed_0 up to failed_4.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89104
2017-11-24 12:17:21 +00:00
Simon McVittie
e49a21e357 DBusString: Add _DBUS_STRING_INIT_INVALID and allow "freeing" it
This means we can finally use patterns like this:

      DBusString buffer = _DBUS_STRING_INIT_INVALID;
      dbus_bool_t ret = FALSE;

      ... some long setup ...

      if (!_dbus_string_init (&buffer))
        goto out;

      ... some long operation ...

      ret = TRUE;

    out:
      ... free things ...
      _dbus_string_free (&buffer);
      ... free more things ...
      return ret;

without having to have a separate boolean to track whether buffer has
been initialized.

One observable difference is that if s is a "const" (borrowed pointer)
string, _dbus_string_free (&s) now sets it to be invalid. Previously,
it would have kept its (borrowed pointer) contents, which seems like
a violation of least-astonishment.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89104
2017-11-24 12:17:17 +00:00
Simon McVittie
608a453b73 DBusString: Reverse the sense of ->invalid
It's easier to implement a stack-allocated string that is valid to
free (but for no other purpose) if we consider all-bits-zero to be
invalid.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89104
2017-11-24 12:16:56 +00:00
Simon McVittie
85e89a4e9b Remove references to test/data/incomplete-messages too
Signed-off-by: Simon McVittie <smcv@collabora.com>
2017-11-15 15:28:11 +00:00
Simon McVittie
6fb2f4c00a tests: Remove leftover references to valid-messages directory
Now that the directory doesn't exist in git, the embedded tests fail
in a clean git checkout.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2017-11-15 15:04:44 +00:00
Simon McVittie
336ff50c97 Update NEWS for 1.13.x test changes
Signed-off-by: Simon McVittie <smcv@collabora.com>
2017-11-15 14:01:16 +00:00
Simon McVittie
09076dfea0 Remove test data in the "message builder" domain-specific language
These tests were disabled by commit 9c3d566, which rewrote the D-Bus
type system to be fully recursive, back in 2005. The message builder
was subsequently removed by commit 9d21554, also in early 2005.

It will probably take significant work to turn these files into
test-cases that use the current D-Bus type system and so can be run
this decade. Until that work is done, let's not ship them: we can
always fetch them from git history if we want them.

The single .message-raw file can still be read and has been retained,
although it hasn't actually tested the intended failure mode since
2005 due to changes to the D-Bus specification (it is a wire-protocol
version 0 message, and the recursive type system introduced in commit
9c3d566 changed the wire-protocol version to 1).

Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103758
2017-11-15 13:59:05 +00:00
Simon McVittie
2b98220e5f _dbus_test_diag: Flush stdout after each diagnostic
If we crash, we'll want to know what the most recent diagnostic was.

Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103601
2017-11-15 13:18:22 +00:00
Simon McVittie
2aa190aef6 dispatch test: Output finer-grained TAP
This lets us see which bits are painfully slow. (Spoilers:
check_existent_service_no_auto_start.)

Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103601
2017-11-15 12:12:46 +00:00
Simon McVittie
3baad75ca9 test-bus*: Output TAP directly
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103601
2017-11-15 12:12:43 +00:00
Simon McVittie
ea43f3db48 test-dbus: Produce machine-readable TAP output
See http://testanything.org/ for more information on TAP.

Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103601
2017-11-15 12:12:40 +00:00
Simon McVittie
fc30e312ea bus: Silence the output of the test services when doing OOM testing
The echo service frequently fails to connect to the bus when we are
testing OOM code paths, again causing a lot of noise in the log.

Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103601
2017-11-15 12:12:27 +00:00
Simon McVittie
39ef65d07d bus: Silence most log messages when testing OOM handling
In parts of the OOM testing, our logging produces multiple megabytes
of output. Let's not do that.

Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103601
2017-11-15 12:12:23 +00:00
Simon McVittie
13b640544d Unix: Flush stdout and stderr streams before forking
stdout and stderr are close-on-exec and buffered, so we can't rely on
their buffers being empty. If we continue to execute application code
after forking (as opposed to immediately exec()ing), then the child
process might later flush the libc stdio buffers, resulting in
output that is printed by the parent also being printed by the child.

In particular, test-bus.log sometimes grows extremely large for
this reason, because this test repeatedly attempts to carry out
legacy activation.

Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103601
2017-11-15 12:12:18 +00:00
Simon McVittie
3d2300efc3 Prefer to use _dbus_test_fatal() for assertion failures in tests
This is a little more self-documenting - it justifies why it's
acceptable to fail hard on out-of-memory conditions. _dbus_test_fatal()
isn't compiled unless we are compiling embedded tests, so compiling
with embedded tests disabled provides reasonable confidence that we
aren't using _dbus_test_fatal() inappropriately.

Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103601
2017-11-15 12:12:15 +00:00
Simon McVittie
2edee28f15 Use _dbus_test_fatal to include more detail in test failure diagnostics
Unlike _dbus_assert_not_reached(), this new function takes a printf-style
format string, so we don't need to use a _dbus_warn() to explain why
the failure occurred (unless the failure message is multi-line).

Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103601
2017-11-15 12:12:12 +00:00
Simon McVittie
ed40af9284 Embedded tests: Emit TAP diagnostics instead of printf
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103601
2017-11-15 12:11:54 +00:00
Simon McVittie
5ffb709b42 Add utility functions to emit TAP diagnostics and fatal errors
Reviewed-by: Philip Withnall <withnall@endlessm.com>
[smcv: Add an explanatory comment as suggested]
Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103601
2017-11-15 12:11:21 +00:00
Simon McVittie
fb9e8e4e0c Do not export dbus_internal_do_not_use_run_tests if unused
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103601
2017-11-15 12:08:21 +00:00
Simon McVittie
3f3498c9c2 Windows autolaunch: Turn stdout spam into stderr spam
This is still not how warnings and diagnostics should be done
(the advice should probably be included in the DBusError) but at least
this way it won't interfere with machine-readable output on stdout.
See also https://bugs.freedesktop.org/show_bug.cgi?id=103756

Reviewed-by: Philip Withnall <withnall@endlessm.com>
[smcv: Added a reference to #103756]
Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103601
2017-11-15 12:07:47 +00:00
Simon McVittie
789750feee Remove commented-out printf debugging
Printing to stdout would interfere with generating TAP syntax.

Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103601
2017-11-15 12:07:22 +00:00
Simon McVittie
9daf727236 Update NEWS for 1.13.x
Signed-off-by: Simon McVittie <smcv@collabora.com>
2017-11-14 12:25:50 +00:00
Thomas Zajic
c9ce0a7059 Add a missing space in logging output
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103729
2017-11-14 12:24:27 +00:00
Simon McVittie
85830f4c5b Merge branch 'dbus-1.12' 2017-11-13 17:13:27 +00:00
Simon McVittie
7f92c3cfcf Start 1.12.4
Signed-off-by: Simon McVittie <smcv@collabora.com>
2017-11-13 17:11:27 +00:00
Simon McVittie
0f0968336b 1.12.2
Signed-off-by: Simon McVittie <smcv@collabora.com>
2017-11-13 13:35:55 +00:00
Simon McVittie
06c105545f Update NEWS for 1.12.x
Signed-off-by: Simon McVittie <smcv@collabora.com>
2017-11-10 16:24:59 +00:00
Simon McVittie
3d96f366f1 Update NEWS for 1.13.x
Signed-off-by: Simon McVittie <smcv@collabora.com>
2017-11-10 16:24:47 +00:00
Simon McVittie
1a29dc8544 bus_connections_setup_connection: If we can't set it up, log why
While reviewing fd.o#101354, Philip Withnall pointed out that if we
rejected a connection in the new code there, we didn't log why. It
turns out we didn't log that in the more normal code path either.
Redo the error handling so that failure to set up a connection
is logged.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103592
(cherry picked from commit 56847ae818)
2017-11-10 16:22:20 +00:00
Simon McVittie
56847ae818 bus_connections_setup_connection: If we can't set it up, log why
While reviewing fd.o#101354, Philip Withnall pointed out that if we
rejected a connection in the new code there, we didn't log why. It
turns out we didn't log that in the more normal code path either.
Redo the error handling so that failure to set up a connection
is logged.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103592
2017-11-10 16:21:07 +00:00
Simon McVittie
293cbd03e3 Update NEWS for 1.13.x
Signed-off-by: Simon McVittie <smcv@collabora.com>
2017-11-10 16:20:25 +00:00
Simon McVittie
35238ed567 Update NEWS for 1.12.x
Signed-off-by: Simon McVittie <smcv@collabora.com>
2017-11-10 16:20:02 +00:00
Simon McVittie
b672a683be travis-ci: Enable/disable more features in various builds
In the debug build, enable features that are off by default. In the
reduced build, explicitly disable features, some of which are
on by default. In the legacy build, check that we can compile the
default feature-set without inotify, dnotify, systemd, etc.

Reviewed-by: Philip Withnall <withnall@endlessm.com>
[smcv: Rebase onto 1.13.x branch, fix minor conflicts]
Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354
(cherry picked from commit 3c031ef5aa)
2017-11-10 16:10:15 +00:00
Simon McVittie
010223b6d2 DBusNonceFile: Don't rely on caller preallocating the object
If we combine the dbus_new0, populating the DBusString members and the
actual creation of the file, RAII-style, then we never need to worry
about a partially-initialized or uninitialized DBusNonceFile becoming
visible to a caller.

Similarly, if we combine deletion of the file, freeing of the
DBusString members, freeing the structure and clearing the pointer to
the structure, then we can never be in an inconsistent situation,
except during the actual implementation of _dbus_noncefile_delete().

Note that there are two implementations each of
_dbus_noncefile_create() and _dbus_noncefile_delete(). This is because
on Unix we must use a subdirectory of _dbus_get_tmpdir() (the nonce
filename is not created atomically, so that would not be safe), while
on Windows we use the directory directly (the Windows temp directory
is private to a user, so this is OK).

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103597
2017-11-07 12:43:52 +00:00
Simon McVittie
a208e02421 _dbus_accept_with_noncefile: Don't leak nonce
This was always leaked, both on success and on error.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103597
(cherry picked from commit 37d5af203c)
2017-11-07 11:43:37 +00:00
Simon McVittie
d000891624 do_noncefile_create: Avoid freeing uninitialized memory on error
We could free all of these without having ever successfully
initialized them.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103597
(cherry picked from commit 6d08f5c04e)
2017-11-07 11:43:34 +00:00
Simon McVittie
208af9a447 do_check_nonce: Don't free uninitialized memory on OOM
If _dbus_string_init() fails, it doesn't guarantee that the string
is initialized to anything in particular. Worse, if
_dbus_string_init (&buffer) fails, p would never have been initialized
at all, due to the use of the short-circuiting || operator.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103597
(cherry picked from commit 0ea0e4b0fd)
2017-11-07 11:43:31 +00:00
Simon McVittie
37d5af203c _dbus_accept_with_noncefile: Don't leak nonce
This was always leaked, both on success and on error.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103597
2017-11-07 11:38:53 +00:00
Simon McVittie
6d08f5c04e do_noncefile_create: Avoid freeing uninitialized memory on error
We could free all of these without having ever successfully
initialized them.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103597
2017-11-07 11:38:43 +00:00
Simon McVittie
0ea0e4b0fd do_check_nonce: Don't free uninitialized memory on OOM
If _dbus_string_init() fails, it doesn't guarantee that the string
is initialized to anything in particular. Worse, if
_dbus_string_init (&buffer) fails, p would never have been initialized
at all, due to the use of the short-circuiting || operator.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103597
2017-11-07 11:38:26 +00:00