Commit Graph

8746 Commits

Author SHA1 Message Date
Matthias Clasen
64cd43029e Revert "Add GBase64Encoder and Decoder"
This reverts commit b2c11516e2.
2024-05-05 14:58:43 -04:00
Matthias Clasen
b2c11516e2 Add GBase64Encoder and Decoder
These are GConverter implementations that convert to/from
base64 encoding.

Originally written by Christian Persch.

Fixes: #305
2024-05-05 14:53:14 -04:00
Simon McVittie
43c5af517c gdocumentportal: Treat more error codes as a permissions error
If the file to be added is on a read-only filesystem, opening read/write
will fail with EROFS. In this case we should fall back to opening it
read-only, the same way we already do if write access is forbidden by
DAC or MAC.

An easy way to reproduce this test failure is to build and test GLib
in a podman container, with its source code read-only and its build
directory read/write:

    podman run --rm -it \
    -v $(pwd):$(pwd):ro \
    -v $(pwd)/_build:$(pwd)/_build:rw \
    -w $(pwd) ...

Before this commit, the dbus-appinfo test would fail, because opening
${srcdir}/gio/tests/org.gtk.test.dbusappinfo.flatpak.desktop read/write
would fail with EROFS.

For completeness, give similar handling to the other error codes
documented in Linux open(2) that might succeed if re-attempted using
read-only access: according to that documentation, we could get EPERM
if opening read/write is prevented by fcntl F_ADD_SEALS, or ETXTBSY
if the file is an executable that is currently being run.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 18:34:04 +01:00
Simon McVittie
8c533510ee gdocumentportal: Factor out opening_ro_might_succeed()
No functional change.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 18:33:37 +01:00
Ray Strode
c7caf98646 Merge branch 'track-bus-name-owners-for-signal-subscriptions' into 'main'
Track bus name owners for signal subscriptions

See merge request GNOME/Security/glib!1
2024-05-01 13:34:40 +00:00
Simon McVittie
96e3190aef tests: Ensure that unsubscribing with GetNameOwner in-flight doesn't crash
This was a bug that existed during development of this branch; make sure
it doesn't come back.

This test fails with a use-after-free and crash if we comment out the
part of name_watcher_unref_watched_name() that removes the name watcher
from `map_method_serial_to_name_watcher`.

It would also fail with an assertion failure if we asserted in
name_watcher_unref_watched_name() that get_name_owner_serial == 0
(i.e. that GetNameOwner is not in-flight at destruction).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 13:42:27 +01:00
Simon McVittie
f6d1b5471a tests: Add a test for signal filtering by well-known name
The vulnerability reported as GNOME/glib#3268 can be characterized
as: these signals from an attacker should not be delivered to either
the GDBusConnection or the GDBusProxy, but in fact they are (in at
least some scenarios).

Reproduces: https://gitlab.gnome.org/GNOME/glib/-/issues/3268
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 13:42:27 +01:00
Simon McVittie
fc0ee92072 tests: Add a test for matching by two well-known names
The expected result is that because TEST_CONN_SERVICE owns
ALREADY_OWNED_NAME but not (yet) OWNED_LATER_NAME, the signal will be
delivered to the subscriber for the former but not the latter.
Before #3268 was fixed, it was incorrectly delivered to both.

Reproduces: https://gitlab.gnome.org/GNOME/glib/-/issues/3268 (partially)
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 13:42:27 +01:00
Simon McVittie
d4b6537651 gdbusconnection: Don't deliver signals if the sender doesn't match
Otherwise a malicious connection on a shared bus, especially the system
bus, could trick GDBus clients into processing signals sent by the
malicious connection as though they had come from the real owner of a
well-known service name.

Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/3268
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 13:42:27 +01:00
Simon McVittie
683b14b981 gdbus: Track name owners for signal subscriptions
We will use this in a subsequent commit to prevent signals from an
impostor from being delivered to a subscriber.

To avoid message reordering leading to misleading situations, this does
not use the existing mechanism for watching bus name ownership, which
delivers the ownership changes to other main-contexts. Instead, it all
happens on the single thread used by the GDBusWorker, so the order in
which messages are received is the order in which they are processed.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-01 13:27:24 +01:00
Philip Withnall
fd93e12669
gdbusconnection: Fix a crash on arg0 matching
If a connection has two signal subscriptions active for the same signal,
one with arg0 matching and one without, a signal which doesn’t contain
an arg0 value (i.e. `g_dbus_message_get_arg0()` returns `NULL`) will
cause `NULL` to be passed to `strcmp()` when checking for a match
against the signal subscription which *has* arg0 matching, causing a
crash.

Fix that by adding the obvious `NULL` check, and add a unit test.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Fixes: #3342
2024-04-30 18:33:57 +01:00
Julian Sparber
0144feb41f GApplication: Allow multiple parameters for D-Bus activation
D-Bus Activation allows passing an array of parameters. Allow apps to
export actions that accept tuples to match the number of elements in the
parameters so the full potential of the D-Bus interface can be used.

Closes: https://gitlab.gnome.org/GNOME/glib/-/issues/3333
2024-04-29 16:30:36 +02:00
Philip Withnall
d2f5cd4153
tests: Fix a -Wmaybe-uninitialized warning in gdbus-serialization test
It’s a false positive, but easy enough to squash.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-25 23:57:55 +01:00
Philip Withnall
9f3322c784
gdbusdaemon: Disable scan-build for GDBusDaemon name refcounting
See the code comment. scan-build can’t handle analysis over the
refcounts, so consistently complains about potential use-after-free
errors in the code, essentially because:
 * It understands `name_unref()`, but completely ignores `name_ref()`
 * The code often calls `name_unref()` on the ‘wrong’ pointer, in the
   sense that it knows that if another struct exists, that struct holds
   a ref on a `Name`, but without actually having a pointer to the
   `Name`. So the code calls `name_unref (name); name_unref (name)`.
   That’s valid, but quite understandably looks like a recipe for a
   use-after-free.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #1767
2024-04-25 23:57:51 +01:00
Philip Withnall
672a33002e
gunixmounts: Squash a static analyser false positive
scan-build thinks that there can be a `NULL` pointer dereference of
`error` here because it doesn’t understand that the function return
value and `GError` are related: when a valid return value is returned,
the error is `NULL` and vice-versa.

Try and make that clearer to the static analyser by checking whether the
error is `NULL`, rather than the return value.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #1767
2024-04-25 23:57:46 +01:00
Philip Withnall
a1ff120a98
gsrvtarget: Silence false positive NULL pointer dereference
scan-build thinks there could be a `NULL` pointer dereference of
`t->data` here. It’s wrong, so add an assertion to try and help it
understand the control flow.

The loop is exited as soon as a target is found whose weight is greater
than or equal to a random value between 0 and the sum of all the weights
in the set of remaining targets in the loop. By definition, the last
target in the loop always satisfies this condition, so a target will
always be chosen, and hence `t` will never be `NULL` within the loop.

`t->data` will never be `NULL` by construction of the target list.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #1767
2024-04-25 23:57:41 +01:00
Philip Withnall
066298b6ef
gdbusconnection: Fix a false positive memory leak from scan-build
scan-build thinks that `data` could be leaked. It’s not, though; it’s
passed as the `user_data` to `g_dbus_connection_register_object()` along
with its free function.

Try and persuade scan-build that there’s no leak by annotating the
transfer.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #1767
2024-04-25 23:57:36 +01:00
Philip Withnall
4894168631
gproxyaddressenumerator: Strengthen some type assertions
scan-build was complaining that `dest_hostname` and `dest_protocol` were
used after being freed, which could potentially happen if the code is
built with `G_DISABLE_CHECKS`. This is a false positive, because the
state of types in the program should be the same regardless of whether
`G_DISABLE_CHECKS` is used.

However, the code did smell. If we are trying to free things and return
gracefully if the underlying socket address enumerator returns something
of the wrong type, why not free the rest of the function’s state, or
skip the invalid address and move on to the next one? Or if we are trying
to make an assertion, why bother freeing some temporary data at all?
This halfway house doesn’t make sense.

So turn the `g_return_val_if_fail()` into a full assertion.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #1767
2024-04-25 23:16:30 +01:00
Philip Withnall
3e68debb13
xdgmime: Add assertion to silence static analysis false positive
After a lot of loop unwinding, during which I think it might have lost
its knowledge that `cache->buffer != NULL` (from a prior check on line
765), scan-build seems to think that there can be a `NULL` pointer
dereference of `cache->buffer` within `cache_magic_compare_to_data()`.
There can’t be. Add an assertion to try and help the analyser.

Upstreamed as
https://gitlab.freedesktop.org/xdg/xdgmime/-/merge_requests/38.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #1767
2024-04-25 23:16:08 +01:00
Philip Withnall
ff4c17bc30
gnetworkmonitornetlink: Refactor error handling in read_netlink_messages()
scan-build thinks that it’s possible for `read_netlink_messages()` to
return `FALSE` and an unset error (or `TRUE` and a set error), and this
belief causes it to emit warnings for code which calls
`read_netlink_messages()`.

That’s not possible, but the function is written in such a way that
following the control flow would be hard for a static analyser. It would
have to work out that `retval` and `local_error == NULL` are identical
on all control flow branches.

Avoid the need for such complex analysis by eliminating `retval` and
just using `local_error` throughout.

This introduces no functional changes to the code.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #1767
2024-04-25 23:16:00 +01:00
Philip Withnall
b3cd9aaa98
gdesktopappinfo: Fix a maybe-uninitialized warning
scan-build thinks that `term_arg` could be used uninitialised. I think
there isn’t a bug here because that use is protected by the
`found_terminal == NULL` check and early return. But perhaps that logic
is a bit too complex for static analysis, so add a default value for the
variable.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #1767
2024-04-25 23:15:55 +01:00
Philip Withnall
e7aa0039b9
gsocks5proxy: Rework functions to separate length and success/failure
The previous approach was to return a length as a `gssize`, with
negative values indicating failure. That works fine, but causes a lot of
signed/unsigned comparisons or assignments.

Tidy the code up by splitting success from length, returning success as
a boolean, and length as a `size_t*` out argument. This introduces no
functional changes, but does tidy the code up and fix some compiler
integer warnings.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-25 00:39:13 +01:00
Philip Withnall
6e362ce3b6
gio: Fix various implicit conversions from size_t to smaller types
Basically various trivial instances of the following MSVC compiler
warning:
```
../gio/gio-tool-set.c(50): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
```

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-25 00:37:47 +01:00
maxrdz
f0b4f50f66
gfileinfo: Fixed broken link to gio/file-attributes.html
Looks like the original author mixed up where the link label and the
link URL goes. :p

Previously the link would point to "https://docs.gtk.org/gio/file
attributes", with a space and no file extension.
2024-04-23 14:33:45 -07:00
Simon McVittie
26a3fb8518 gdbusconnection: Stop storing sender_unique_name in SignalData
This will become confusing when we start tracking the owner of a
well-known-name sender, and it's redundant anyway. Instead, track the
1 bit of data that we actually need: whether it's a well-known name.

Strictly speaking this too is redundant, because it's syntactically
derivable from the sender, but only via extra string operations.
A subsequent commit will add a data structure to keep track of the
owner of a well-known-name sender, at which point this boolean will
be replaced by the presence or absence of that data structure.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-04-23 21:42:24 +01:00
Simon McVittie
7d21b719ed gdbusconnection: Factor out remove_signal_data_if_unused
No functional change, just removing some nesting. The check for whether
signal_data->subscribers is empty changes from a conditional that tests
whether it is into an early-return if it isn't.

A subsequent commit will add additional conditions that make us consider
a SignalData to be still in use and therefore not eligible to be removed.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-04-23 21:42:24 +01:00
Simon McVittie
5d7ad6897c gdbusconnection: Factor out add_signal_data()
No functional changes.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-04-23 21:42:24 +01:00
Simon McVittie
816da60571 gdbusconnection: Factor out signal_data_new_take()
No functional changes, except that the implicit ownership-transfer
for the rule field becomes explicit (the local variable is set to NULL
afterwards).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-04-23 21:42:24 +01:00
Simon McVittie
8dfea5609e gdbusconnection: Move SignalData, SignalSubscriber higher up
Subsequent changes will need to access these data structures from
on_worker_message_received(). No functional change here, only moving
code around.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-04-23 21:42:24 +01:00
Simon McVittie
1e648b677f gdbusprivate: Add symbolic constants for the message bus itself
Using these is a bit more clearly correct than repeating them everywhere.
To avoid excessive diffstat in a branch for a bug fix, I'm not
immediately replacing all existing occurrences of the same literals with
these names.

The names of these constants are chosen to be consistent with libdbus,
despite using somewhat outdated terminology (D-Bus now uses the term
"well-known bus name" for what used to be called a service name,
reserving the word "service" to mean specifically the programs that
have .service files and participate in service activation).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-04-23 21:41:53 +01:00
Simon McVittie
fd265663f2 tests: Add test coverage for signals that match the message bus's name
This is a special case of unique names, even though it's syntactically
a well-known name.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-04-23 19:14:32 +01:00
Simon McVittie
984354e02d tests: Add a test-case for what happens if a unique name doesn't exist
On GNOME/glib#3268 there was some concern about whether this would
allow an attacker to send signals and have them be matched to a
GDBusProxy in this situation, but it seems that was a false alarm.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-04-23 19:14:32 +01:00
Simon McVittie
14c3d6938e tests: Add support for subscribing to signals from a well-known name
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-04-23 19:14:32 +01:00
Simon McVittie
124b4571bb tests: Add a data-driven test for signal subscriptions
This somewhat duplicates test_connection_signals(), but is easier to
extend to cover different scenarios.

Each scenario is tested three times: once with lower-level
GDBusConnection APIs, once with the higher-level GDBusProxy (which
cannot implement all of the subscription scenarios, so some message
counts are lower), and once with both (to check that delivery of the
same message to multiple destinations is handled appropriately).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-04-23 19:08:19 +01:00
Ondrej Holy
dbb7a12a96 gunixmounts: Use fallback if libmount monitoring fails
The recently added libmount-based unix mount monitoring may fail when the
device exceeds inotify limits. Let's fallback to the older implementation
in case of the `mnt_monitor_get_fd` function failure. This among others
fixes tracker-miners failures caused by seccomp rules.

Fixes: https://gitlab.gnome.org/GNOME/tracker-miners/-/issues/315
2024-04-23 12:59:40 +02:00
Michael Catanzaro
81eaabb308 Merge branch 'completion-bins' into 'main'
completion: Invoke the command being completed

See merge request GNOME/glib!4013
2024-04-17 18:04:02 +00:00
Philip Withnall
70c0f3bff6
completion: Rework quoting in gsettings completion script
This is a partial revert and rework of commit
c79575362e, for the `gsettings` script
only (the other completion scripts are fine).

I blindly added quoting to everything shellcheck told me to, without
testing it properly.

As it turns out, the `$schemadir` argument to `gsettings` invocations
was deliberately not quoted, so that it would expand to zero arguments
if unset, and two arguments (`--schemadir /some/path`) if set earlier in
the command-being-completed.

Quoting it meant that it expanded to one argument (the empty string) if
unset, which caused the `gsettings` subcommands to fail, and hence any
further tab completion to fail.

Fix that as suggested on https://www.shellcheck.net/wiki/SC2086 by
turning `schemadir` into an array, which either has zero members if
unset, or two members if set.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-17 17:43:50 +01:00
Philip Withnall
295a6fb965
completion: Add missing copyright and licensing headers
The copyright entries come from looking at `git log gio/completion/*`
and, in particular, `git log -- gio/gsettings-bash-completion.sh` (etc.)
as the files were moved after being originally written, and haven’t
really changed since.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #1415
2024-04-17 17:43:44 +01:00
Philip Withnall
cc22637856
completion: Invoke the command being completed
As suggested by Ville Skyttä in
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4012#note_2084405,
make sure to invoke the copy of the command which is being completed
when asking for completions of a given subcommand.

This avoids accidentally invoking any old `gdbus`/`gresource`/etc.
binary which is hanging around in another part of `$PATH`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-17 17:43:38 +01:00
Philip Withnall
8138246ab8
inotify: Add license and copyright headers to meson.build
The copyright from `git log gio/inotify/meson.build` is now included in
the file header. The following commits are too trivial to be
copyrightable:
 - d10be6102f
 - 03e86d000f
 - 1741fc2c6e
 - 8733d172a3

The file was contributed while the `COPYING` file for GLib was
LGPL-2.1-or-later, so was previously implicitly licensed as that.
Let’s make that explicit.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #1415
2024-04-17 15:46:23 +01:00
Philip Withnall
417f6a4bde
inotify: Trivially add SPDX-License-Identifier to inotify files
The license and copyright are already stated in human-readable form in
these files, so this should be uncontroversial.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #1415
2024-04-17 15:46:11 +01:00
Philip Withnall
34050a5c12
codegen: Add license and copyright headers to remaining files
The `.flake8` file has a trivial version history, so the copyright is
straightforward from that.

`meson.build` has a more complex history, but the only significant
contributions were from Centricular. From `git log
gio/gdbus-2.0/codegen/meson.build`, the other (following) commits are
too trivial to be copyrightable:
 - d10be6102f
 - 30b25a6fd9
 - 95fa229f34
 - 631c3534b7
 - 00d7568e4f
 - 9734e4854e
 - 65be80c3ed
 - 66e4ba806a
 - a1c78d63ef
 - a73ca336aa
 - 19353017a7
 - b4231844a2
 - 4cb945d780
 - 4ce58df854
 - e2433308c4
 - 013980d839

Both files were contributed while the `COPYING` file for GLib was
LGPL-2.1-or-later, so both were previously implicitly licensed as that.
Let’s make that explicit.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #1415
2024-04-17 15:33:24 +01:00
Philip Withnall
68d8f721f3
codegen: Trivially add SPDX-License-Identifier to codegen Python files
The license and copyright are already stated in human-readable form in
these files, so this should be uncontroversial.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #1415
2024-04-17 15:31:50 +01:00
Philip Withnall
869ef92858 Merge branch 'shellcheck-completions' into 'main'
tests: Enable shellcheck for bash completion scripts

See merge request GNOME/glib!4012
2024-04-17 07:43:12 +00:00
Jan Tojnar
156e0c865a docs: Fix broken links
The file was renamed in 5d80471d4b.
2024-04-16 14:33:45 +01:00
Philip Withnall
827bca3212
completion: Ignore SC2207 for COMPREPLY assigments
Using the same justification as in
https://gitlab.gnome.org/GNOME/dconf/-/merge_requests/81#note_2083220:
it’s hard to get this right, with error handling, in a way which is
understandable to people reading it, and which both bash and shellcheck
will be happy with.

On the assumption that none of the completions generated by any of these
utilities will include ‘problematic’ characters (ones which would cause
word splitting or globbing in bash), just ignore the shellcheck
warnings. Note that I have not actually closely verified that these
utilities can’t return ‘problematic’ characters.

This means we can enable shellcheck, with fatal warnings, for these
scripts, and hence catch future regressions.

If someone wants to improve the handling of globbing/word splitting in
some/all of these array assignments in future, the shellcheck disables
can be removed.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-16 14:09:36 +01:00
Philip Withnall
6024fb9753
completion: Quote argument to unset
Otherwise it gets globbed and the wrong thing potentially gets unset.
Spotted by shellcheck.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-16 14:08:39 +01:00
Philip Withnall
17f0cad2c7
completion: Drop some unused variables
Spotted by shellcheck.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-16 14:08:08 +01:00
Philip Withnall
7ad93a0c95
completion: Use read -r rather then plain read
This means that backslashes in the input (which is unlikely, but I guess
possible) won’t affect line splitting. Spotted by shellcheck.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-16 14:07:12 +01:00
Philip Withnall
b1ef6a125e
completion: Quote variable dereferences within variable dereferences
Otherwise they could get split. Spotted by shellcheck.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-16 14:06:13 +01:00
Philip Withnall
d3d811f4e5
completion: Split declaration and assignment of variables
Having them on the same line masks failure of the subcommand generating
the value being assigned. Spotted by shellcheck.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-16 14:05:04 +01:00
Philip Withnall
a7ad2a4c3a
completion: Drop unnecessary $ from variables in arithmetic expressions
It’s not needed, according to shellcheck.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-16 14:03:19 +01:00
Philip Withnall
c79575362e
completion: Add missing quoting
As suggested by shellcheck.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-16 13:58:49 +01:00
Philip Withnall
aaf715a046
completion: Stop using old backtick quoting for subcommands
Fixes a shellcheck warning.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-16 13:54:33 +01:00
Philip Withnall
f95e8b4e7c
completion: Add shellcheck shell hints to all completion scripts
Because completion scripts are not executed directly, they don’t have a
shebang line, so shellcheck can’t be sure which shell syntax to use for
them. Help it out.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-16 13:51:44 +01:00
Michael Catanzaro
5c8fbc3cda Merge branch 'scan-build' into 'main'
Fix various bugs found by scan-build and refresh scan-build config in CI

See merge request GNOME/glib!4005
2024-04-15 15:47:45 +00:00
Michael Catanzaro
e831627881 Merge branch '3310-subprocess-sigpipe' into 'main'
gsubprocess: Globally ignore SIGPIPE

Closes #3310

See merge request GNOME/glib!3991
2024-04-15 15:33:00 +00:00
Philip Withnall
ad0532f2bf
xdgmimeglob: Fix a memory leak on a duplicate-entry path
Rather than `strdup()`ing strings when passing them into
`_xdg_glob_list_append()`, `strdup()` them *inside* the function
instead.

This avoids a leak in the case that the list entry (tuple of `data` and
`mime_type`) already exists in the list.

This has been upstreamed as
https://gitlab.freedesktop.org/xdg/xdgmime/-/merge_requests/36.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-12 18:45:52 +01:00
Philip Withnall
ae3bd19108
gresource: Improve resource unregistration performance slightly
Rather than iterating over the list twice: once to find the resource,
and once to re-find its link and delete it, just use
`g_list_delete_link()` to delete what was found.

This has the lovely side-effect of squashing a false positive from
scan-build, which thought there was a use-after-free of `resource` in
the caller, due to `g_resource_unref()` being called on it here.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #1767
2024-04-12 18:45:46 +01:00
Philip Withnall
1ed199a881
tests: Use g_assert_*() rather than g_assert() in gdbus-export tests
It won’t get compiled out with `G_DISABLE_ASSERT`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-12 18:45:39 +01:00
Philip Withnall
3f30ec86cd
gdbusconnection: Fix user_data leaks on error
There were a couple of functions in `GDBusConnection` which take a
`user_data` argument, but which then leak it if they error out early.

A true positive spotted by scan-build!

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #1767
2024-04-12 18:45:31 +01:00
Philip Withnall
b8225c905b
gdbusconnection: Ensure out_serial return value is always set
There were some error paths where it wasn’t set, returning an
uninitialised value to the caller.

Spotted by scan-build.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #1767
2024-04-12 18:45:03 +01:00
Philip Withnall
978ca4731c
gactiongroup: Add a missing array termination annotation
It might not actually be needed (I haven’t checked if the default is
correct), but it certainly does no harm and makes things explicit.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-12 13:56:20 +01:00
Philip Withnall
3ec4ba4d1b
gactiongroup: Minor copyediting of documentation, comments and warnings
No functional changes.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-12 13:56:07 +01:00
Sudhanshu Tiwari
527e696553 Removed an extra new line in gio/gactiogroup.c 2024-04-12 13:55:51 +01:00
Sudhanshu Tiwari
a43ee8991e Ports the documentation comments in gio/gactiongroup.c to GI-Docgen 2024-04-12 13:55:51 +01:00
L. E. Segovia
5d08fb2e45 gunixmounts: Fix typo in comment regarding Android API level 2024-04-02 08:48:39 -03:00
L. E. Segovia
e0fca3e7a7 gunixmounts: Use __ANDROID__ to test for the OS, not __BIONIC__
See https://android.googlesource.com/platform/bionic/+/HEAD/docs/defines.md
2024-04-02 08:44:58 -03:00
L. E. Segovia
0da4b1bf31 gio-launch-desktop, gmessages: Fix journald support using __BIONIC__ to skip support on Android
As per the Bionic docs, this functionality is Android, not bionic specific.

See: https://android.googlesource.com/platform/bionic/+/HEAD/docs/defines.md
2024-04-02 08:40:48 -03:00
Philip Withnall
2cee8e3d06 Merge branch 'port-gaction-comments-2' into 'main'
Port the remaining documentation comments in `gio/gaction.c` to GI-Docgen

See merge request GNOME/glib!3986
2024-04-01 15:33:54 +00:00
Sudhanshu Tiwari
57d6b945f1 Ported the remaining documentation comments in gio/gaction.c to GI-Docgen 2024-04-01 16:00:23 +01:00
Philip Withnall
e46f2347d2 Merge branch 'style/spelling' into 'main'
docs: spelling and grammar fixes

See merge request GNOME/glib!3990
2024-04-01 14:13:19 +00:00
Philip Withnall
ef461fb391 gsubprocess: Globally ignore SIGPIPE
Just like we already do in `GSocket`.

This is necessary when using `g_subprocess_communicate()` with a
subprocess which calls `close()` on its stdin FD at some point. `cat`
does this just before exiting, for example.

This causes a `write()` to the stdin pipe in the parent process to fail
with `EPIPE` and `SIGPIPE`. The condition is not detectable in advance,
because the `close()` call could happen after the `GMainContext` has
dispatched a `g_subprocess_communicate()` callback.

If it weren’t for the `SIGPIPE`,`g_subprocess_communicate()` would be
able to handle the `EPIPE` just fine. `SIGPIPE` seems like a default
error handling path which was useful in 1980 for writing pipe-heavy
command line apps, but which is more of a broken stair for writing
larger modern apps which have more than one data flow path.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Fixes: #3310
2024-04-01 14:41:33 +01:00
Ville Skyttä
b20647c2e2 docs: spelling and grammar fixes
Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
2024-04-01 11:01:06 +00:00
Ville Skyttä
bf1508fa76 completion: make gsettings work in nounset mode
With the shell in nounset mode, an error is emitted on referencing
`schemadir` as it is not initialized in all code paths.

Initialize to an empty string to fix.

Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
2024-04-01 10:31:34 +00:00
Philip Withnall
ed4f29cce8 gio: Change ‘unrecognised’ to ‘unrecognized’ in various user-visible places
The source language of GLib is technically en-US, so we should
consistently use en-US spellings.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3269
2024-03-27 12:07:42 +00:00
Calvin Walton
013980d839 Use the python found by meson as the interpreter for installed scripts
The python interpreter found by `/usr/bin/env python3` is not
necessarily the same installation as the one that's found by meson's
`pymod.find_installation('python')`. This means that even though meson
is checking that the python installation it found includes the
'packaging' module, the scripts might not have access to that module
when run.

For distribution packaging, it's usually desirable to have python script
interpreters be fully specified paths, rather than use `/usr/bin/env`,
to ensure the scripts run using the expected python installation (i.e.
the one where the python 'packaging' dependency is installed).

The easiest way to fix this is to set the script interpreter to the
`full_path()` of the python interpreter found by meson. The specific
python interpreter that will be used can be selected through the use of
a meson machine file by overriding the "python" program. Many
distributions already have this set up using meson packaging helpers.
2024-03-25 15:17:59 -04:00
Michael Catanzaro
e124c34ad6 Merge branch 'io-priority-docs' into 'main'
gio: Fix docs links to description of I/O priority

See merge request GNOME/glib!3978
2024-03-22 15:16:11 +00:00
Philip Withnall
71d60faef3 Merge branch 'copy-move-async-with-closures' into 'main'
Add g_file_copy_async_with_closures() and g_file_move_async_with_closures()

See merge request GNOME/glib!3939
2024-03-22 00:55:07 +00:00
Philip Withnall
7feeafd9db gio: Fix docs links to description of I/O priority
There are a lot of links to the description of I/O priority in the GIO
docs, and they’re all currently broken since the docs build was ported
to gi-docgen.

Use a simple find and replace (see below) to fix them. This doesn’t port
any of the surrounding docs to gi-docgen format, but should still
improve things overall.
```sh
git search-replace --fix '\[I/O priority\]\[io-priority\]///[I/O priority](iface.AsyncResult.html#io-priority)'
```

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3250
2024-03-22 00:53:05 +00:00
Philip Chimento
64b06c633a gfile: Add g_file_{copy,move}_async_with_closures
g_file_copy_async() and g_file_move_async() are written in a way that is
not bindable with gobject-introspection. The progress callback data can
be freed once the async callback has been called, which is convenient
for C, but in language bindings the progress callback closure is
currently just leaked.

There is no scope annotation that fits how the progress callback should
be treated:

- (scope call) is correct for the sync versions of the functions, but
  incorrect for the async functions; the progress callback is called
  after the async functions return.
- (scope notified) is incorrect because there is no GDestroyNotify
  parameter, meaning the callback will always leak.
- (scope async) is incorrect because the callback is called more than
  once.
- (scope forever) is incorrect because the callback closure could be
  freed after the async callback runs.

This adds g_file_copy_async_with_closures() and
g_file_move_async_with_closures() for the benefit of language bindings.

See: GNOME/gjs#590
2024-03-22 00:20:00 +00:00
Philip Chimento
685d3dfbdc gsettings: Add g_settings_bind_with_mapping_closures()
This is an introspection-friendly version of g_settings_bind_with_mapping.
Having two callbacks that share the same user data is not supported by
girepository, so the existing function is not introspectable.

Closes: #564
2024-03-21 23:38:13 +00:00
Sudhanshu Tiwari
fa5237650b Ported the first 3 documentation comments in gaction.c to gi-docgen 2024-03-20 11:34:33 +00:00
Philip Withnall
e83e4c5535 tests: Mark several additional tests as can_fail on GNU Hurd
These consistently fail on scheduled CI runs, which is not helping our
ability to catch Hurd regressions.

For example, https://gitlab.gnome.org/GNOME/glib/-/jobs/3709402

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

See: #3148
2024-03-19 13:01:26 +00:00
Nirbheek Chauhan
92a97c4f48 meson: Fix a needless recompilation of some gdbus tests
The gdbus-example-objectmanager visibility header was being re-created
on reconfigure, causing a needless rebuild of gdbus tests that were
using the visibility header.

All other invocations of gen_visibility_macros are via custom_target.
2024-03-13 03:32:56 +05:30
Simon McVittie
fb4b780eea glib-compile-resources: Provide placeholders for options with an argument
If we don't do this, the --help text is formatted as though the option
did not expect an argument.

IDENTIFIER is a new translated string, but it is developer-oriented,
so a missing translation is not particularly bad. COMMAND is already
present in translations.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-28 11:28:00 +00:00
Simon McVittie
5622a4a625 gdbus: Add command-line placeholder for ADDRESS
If we don't do this, the --help text is formatted as though the option
did not expect an argument.

This introduces a new translated string, but it is developer-oriented,
so a missing translation is not particularly bad.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-28 11:27:21 +00:00
Philip Withnall
9a661ab970 gsocketclient: Fix a use-after-free in g_socket_client_connected_callback()
The ref held by `data->task` may be the last one on the `GTask`. The
`GTask` stores `attempt->data` as its task data, and so when the `GTask`
is finalised, `attempt->data` is too. `connection_attempt_remove()`
needs to access `attempt->data`, so must be called before the
`g_object_unref()` in this situation.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Fixes: #3266
2024-02-27 09:03:03 +00:00
Philip Withnall
ca4e6f81d2 Merge branch 'wip/oholy/gvolumemonitor-leak' into 'main'
gcontextspecificgroup: Wait until stop_func is done

Closes #3258

See merge request GNOME/glib!3934
2024-02-26 18:06:45 +00:00
Luca Bacci
4337f8f735 GWinHttpFile: Check for matching attributes before sending the HTTP(S) request
We might not need to make an HTTP(S) request at all

Fixes #3080
2024-02-21 11:56:36 +01:00
Luca Bacci
c515f793e5 GWinHttpFile: Set display-name and type at the start of the query_info() function
Those attributes do not need the HTTP(S) request data, so just set them
right away.
2024-02-21 11:52:36 +01:00
Ondrej Holy
bf7d941088 gcontextspecificgroup: Wait until stop_func is done
Currently, the `stop_func` is executed on an extra thread, and the
`g_context_specific_group_remove` function returns before the `stop_func`
finishes. It may happen that the `stop_func` is never executed if the
program terminates soon after calling it. Let's wait until the `stop_func`
is done.

Fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/3258
2024-02-20 13:39:31 +01:00
Philip Withnall
43924f7cf5 Merge branch 'fix-issue-3210' into 'main'
GWinHttpFile: Add support for G_FILE_ATTRIBUTE_STANDARD_TYPE

Closes #3210

See merge request GNOME/glib!3908
2024-02-14 09:22:36 +00:00
Luca Bacci
6ee0772146 GWinHttpFile: Add support for G_FILE_ATTRIBUTE_STANDARD_TYPE
Fixes #3210
2024-02-14 10:06:50 +01:00
Philip Withnall
434d3ff524 docs: Mention GioUnix-2.0 GIR namespace alongside gio-unix-2.0.pc
This should clarify things a little for users of language bindings, who
don’t directly use `.pc` files.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-02-12 17:54:10 +00:00
Philip Withnall
c498c9a8c9 docs: Split out platform specific GIO and GLib documentation
This creates `GioUnix`, `GioWin32`, `GLibUnix` and `GLibWin32`. These
bodies of documentation are in addition to the main, platform agnostic,
documentation for both libraries.

This commit necessarily includes various mechanical changes to update
the repository namespace used in various existing documentation links to
platform specific APIs.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3037
2024-02-12 17:54:10 +00:00
Philip Withnall
0d9170c6b8 gio: Remove unnecessary appinfo_sources variable
There was no obvious logical need to list the `GAppInfo` subclass
sources separately in the build. It makes more sense to add them to the
platform-specific source lists, since they are platform specific.

This will be used in an upcoming commit which generates
platform-specific GIR files, so needs the full platform-specific lists
of sources.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3037
2024-02-12 17:54:10 +00:00
Philip Withnall
f63cc38328 gfiledescriptorbased: Move across typedef from giotypes.h
`GFileDescriptorBased` is in `gio-unix-2.0` rather than `gio-2.0`, so
its types shouldn’t be declared in a header belonging to the latter.

This hasn’t been a problem previously because C is fine with that. But
upcoming commits are going to split the introspection scanning for
`gio-2.0` and `gio-unix-2.0`, and the introspection scanner is a little
more picky about declarations not being spread all over the place.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3037
2024-02-12 17:54:10 +00:00
Philip Withnall
2cacc09398 Merge branch '3231-gir-symbols-cleanup' into 'main'
introspection: Remove various public symbols from newly generated GIRs

Closes #3231

See merge request GNOME/glib!3910
2024-02-09 10:58:29 +00:00
Philip Withnall
71801e445e gthreadedresolver: Move private testing symbols to a private header
The symbols still have to be exported from the library (since they’re
called from unit tests), but there was never any reason for them to be
in a public header.

This means they now disappear from `Gio-2.0.gir`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3231
2024-02-09 10:05:56 +00:00