Commit Graph

8675 Commits

Author SHA1 Message Date
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
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