Commit Graph

21890 Commits

Author SHA1 Message Date
Philip Withnall
ed81cbc9b5 gdbusauthmechanismsha1: Fix race in keyring_acquire_lock()
There was a time-of-check-to-time-of-use (TOCTTOU) race in the keyring
lock code, where it would check the existence of the lock file using
`access()`, then proceed to call `open(O_CREAT | O_EXCL)` to try and
create the lock file once `access()` showed that it didn’t exist.

The problem is that, because this is happening in a shared directory
(`~/.dbus-keyrings`), another process could quite legitimately create
the lock file in the meantime.

Instead, unconditionally call `open()` and ignore errors from it (which
will be returned if the lock file already exists) until it succeeds (or
the code times out).

This eliminates the TOCTTOU race, and simplifies the timeout behaviour
so there aren’t two loops (check for existence, try to create)
happening. It brings this code in line with what dbus.git does (see
`_dbus_keyring_lock()`).

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #1954
2020-05-05 16:07:32 +01:00
Philip Withnall
d6bab03150 gdbusauthmechanismsha1: Fix keyring lock file permissions
Why should it have the sticky bit set? dbus.git sets permissions 0600;
so should GLib.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-05-05 16:07:32 +01:00
Philip Withnall
f4dc46db45 gdbusauthmechanismsha1: Fix return type in precondition guards
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-05-05 16:07:32 +01:00
Philip Withnall
6bf221c441 tests: Isolate directory access for gdbus-server-auth test
When multiple tests were run in parallel, this would race on its access
to `~/.dbus-keyrings` to authenticate with the D-Bus server, since the
keyring directory was not appropriately sandboxed to the unit test.

Use `G_TEST_OPTION_ISOLATE_DIRS` to automatically isolate each unit
test’s directory usage.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #1954
2020-05-05 16:07:32 +01:00
Philip Withnall
6978a4f87a tests: Fix a memory leak in gdbus-server-auth
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-05-05 16:07:32 +01:00
Simon McVittie
da84e9eb26 Merge branch 'wip/pwithnall/2092-stupid-dbus-tests-again' into 'master'
tests: Fix remaining race in gdbus-connection filter test

Closes #1957 and #2092

See merge request GNOME/glib!1476
2020-05-05 14:52:09 +00:00
Philip Withnall
2f171d0ed4 tests: Fix remaining race in gdbus-connection filter test
Commit 721e385 left one remaining race in the filter test, with a
comment associated with it. Unfortunately, the (seemingly unrelated)
changes in #1841 to `GCancellable` seem to have made this remaining race
a lot more likely to fail on FreeBSD than before.

What’s likely to have happened (although I was unable to reproduce the
failure, due to not having a FreeBSD system; I was only able to
reproduce the problem as a 3/1000 failure on Linux, which is still worth
fixing) is that the atomic write of the `FilterData.serial` to be
expected by the filter function sometimes happened after the filter
function had executed, so the expected message was dropped and didn’t
result in an update to the `FilterData` state.

Rework the test so that instead of setting some expectations (on
`FilterData`) in one thread and then checking them in another thread,
the worker thread just unconditionally returns messages from the filter
function to the main thread, and then the main thread checks whether the
expected one has been filtered.

With this change applied, the `gdbus-connection` test passes 5000 times
in a row for me, on Linux; and doesn’t seem to fail any more on the
FreeBSD CI machines over a few runs. (Previously it failed on 4/5 runs.)

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #2092
Fixes: #1957
2020-05-05 13:29:29 +01:00
Philip Withnall
1e598b98e3 Merge branch 'desktop-search-docs' into 'master'
gdesktopappinfo: Note that search results are not filtered

See merge request GNOME/glib!1455
2020-05-05 09:21:18 +00:00
Philip Withnall
5314a20389 gdesktopappinfo: Note that search results are not filtered
Mention in the documentation that (presumably for performance reasons)
the search results from `g_desktop_app_info_search()` are not filtered
by executable presence or hidden attribute.

Perhaps they should be in future, but for now we should at least
document it.

Spotted by Will Thompson.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-05-05 09:29:50 +01:00
Philip Withnall
fbba0d4556 Merge branch 'patch-1' into 'master'
meson: Exclude gosxutils.m when building for iOS

See merge request GNOME/glib!1458
2020-05-04 10:22:56 +00:00
Philip Withnall
bcbcc0ec42 Merge branch '1911-valgrind-suppression' into 'master'
glib.supp: Allow possible leaks of g_type_register_static()

Closes #1911

See merge request GNOME/glib!1474
2020-05-03 09:50:15 +00:00
Philip Chimento
567caa9b29 glib.supp: Allow possible leaks of g_type_register_static()
It seems this should not only be marked reachable, but also for possible
leaks, as the realloc() variant already is.

https://gitlab.gnome.org/GNOME/glib/-/issues/1911
2020-05-02 10:20:43 -07:00
Simon Marchi
cc58ce6a74 gthread: ignore deprecated declarations in static inline functions
With a trivial file that just includes glib.h:

    #include <glib.h>

Compiled with:

    gcc -c test.c \
      -I /tmp/glib/include/glib-2.0/ \
      -I /tmp/glib/lib/x86_64-linux-gnu/glib-2.0/include \
      -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_28 \
      -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_28 \
      -fmax-errors=1 \
      -Werror

We get:

    In file included from /tmp/glib/include/glib-2.0/glib/gasyncqueue.h:32,
                     from /tmp/glib/include/glib-2.0/glib.h:32,
                     from test.c:1:
    /tmp/glib/include/glib-2.0/glib/gthread.h: In function ‘g_rec_mutex_locker_new’:
    /tmp/glib/include/glib-2.0/glib/gthread.h:396:3: error: ‘g_rec_mutex_lock’ is deprecated: Not available before 2.32 [-Werror=deprecated-declarations]
      396 |   g_rec_mutex_lock (rec_mutex);
          |   ^~~~~~~~~~~~~~~~
    /tmp/glib/include/glib-2.0/glib/gthread.h:196:17: note: declared here
      196 | void            g_rec_mutex_lock                (GRecMutex      *rec_mutex);
          |                 ^~~~~~~~~~~~~~~~
    compilation terminated due to -fmax-errors=1.

The problem is that the code in the static inline functions uses
g_rec_mutex_lock, introduced after 2.28.  This code is compiled
regardless of if it's actually used or not.

Suppress the warning by using G_GNUC_BEGIN_IGNORE_DEPRECATIONS /
G_GNUC_END_IGNORE_DEPRECATIONS.  There are precedents for doing that,
for example g_main_context_pusher_new in gmain.h.

Tested by building with all variations of GLIB_VERSION_MIN_REQUIRED /
GLIB_VERSION_MAX_ALLOWED:

    for i in $(seq 26 2 64); do
      gcc -c test.c \
        -I/tmp/glib/include/glib-2.0 \
        -I/tmp/glib/lib/x86_64-linux-gnu/glib-2.0/include \
        -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_$i \
        -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_$i \
        -fmax-errors=1 \
        -Werror
    done

Fixes: #2094
2020-05-01 15:11:37 -04:00
Philip Withnall
fecaa5a5ea Merge branch 'imports' into 'master'
Don't fail a test if optional dependencies are not present

Closes #2083

See merge request GNOME/glib!1448
2020-05-01 17:05:05 +00:00
Philip Withnall
89f964e333 Merge branch 'clang-format-nonliteral' into 'master'
Silence clang errors about -Wformat-nonliteral due to missing intermediate attributes

See merge request GNOME/glib!1440
2020-05-01 16:57:53 +00:00
Philip Withnall
2e2f737f93 Merge branch 'gnulib-isnan' into 'master'
meson: Fix the gnulib checks for isnan* functions

See merge request GNOME/glib!1459
2020-05-01 16:47:40 +00:00
Philip Withnall
8a8de39b81 Merge branch 'valgrind-header-sync' into 'master'
glib: Sync the local modification to glib/valgrind.h to what was upstreamed

See merge request GNOME/glib!1460
2020-05-01 16:34:45 +00:00
Philip Withnall
429da9edd7 Merge branch 'windows-ci-switch-master' into 'master'
CI: Switch to new Windows runners

See merge request GNOME/glib!1466
2020-05-01 16:20:44 +00:00
Philip Withnall
40a64131d1 goption: Treat an empty option context parameter string as NULL
Otherwise the code ends up calling `gettext ("")`, which returns the
current translation’s header. The caller should really have provided a
NULL, parameter string, but the empty string is clear enough.

See
https://gitlab.freedesktop.org/accountsservice/accountsservice/-/merge_requests/56.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-05-01 14:37:30 +01:00
Cheng-Chia Tseng
123e8c9bf6 Update Chinese (Taiwan) translation 2020-05-01 13:16:53 +00:00
Daniel Mustieles
7aa3b675dd Updated Spanish translation 2020-04-30 12:50:49 +02:00
Christoph Reiter
c3645a84b6 CI: Switch to new Windows runners
gitlab will drop cmd.exe support with GitLab 13 so I took the opportunity to
add new runners with Windows 2016 and powershell as default.

These runners are tagged with win32-ps instead of win32. The old runners
will be switched off in the coming weeks.

The main difference is that all commands and env expansions use powershell
and Windows 2016 instead of 2012r2.
2020-04-29 08:56:56 +02:00
Philip Withnall
c9bf247eb9 Merge branch 'update-variant-child-value-docs' into 'master'
gvariant-core: Add a note about memory safety of children

See merge request GNOME/glib!1462
2020-04-28 11:13:43 +00:00
Matthew Leeds
51b822787e gvariant-core: Add a note about memory safety of children
When g_variant_get_child() is called on a variant which has not been
serialized, it serializes it which includes a call to
g_variant_release_children() and therefore means that any children
previously retrieved from the variant are no longer valid (unless
another reference is held on them) and consequently values borrowed from
those children are no longer safe to access. Add a note to the
g_variant_get_child_value() documentation to explain this.

Alternatively, we could say that after the child is freed, values
borrowed from it are no longer valid. But we already have an
implementation which hasn't changed in years which lets them stay valid
if the variant was serialized before the first
g_variant_get_child_value() call.

Here's a demonstration of the memory error:

static const char *get_first_child (GVariant *v) {
    g_autoptr(GVariant) child_v = g_variant_get_child_value (v, 0);
    return g_variant_get_string (child_v, NULL);
}
int main(int argc, char **argv) {
    g_autoptr(GVariant) v = g_variant_new("(@ss)", g_variant_new_string ("hello"), "world");
    const char *child1 = get_first_child (v);
    const char *child2;
    g_variant_get_child (v, 1, "&s", &child2);
    printf ("%s\n", child1); // this is a memory error
    return 0;
}
2020-04-27 17:31:53 -07:00
Martin Storsjö
8bee9febea glib: Sync the local modification to glib/valgrind.h to what was upstreamed
The local change from af0e0cb995 in glib ended upstreamed
as 7359c5fd9f312cddd62146896558d8c9bd2bd4cf in valgrind, with
a few minor adjustments requested from there.

Sync this local modification to what ended up upstreamed, to avoid
any doubt regarding it for future syncs of the whole header.
2020-04-27 22:00:50 +03:00
Martin Storsjö
6cae01c2f5 Silence clang errors about -Wformat-nonliteral due to missing intermediate attributes
By default, meson builds glib with -Werror=format=2, which
implies -Werror=format-nonliteral. With these flags, clang errors
out on e.g. the g_message_win32_error function, due to "format
string is not a string literal". This function takes a format
string, and passes the va_list of the arguments onwards to
g_strdup_vprintf, which is annotated with printf attributes.

When passing a string+va_list to another function, GCC doesn't warn
with -Wformat-nonliteral. Clang however does warn, unless the
functions themselves (g_message_win32_error and set_error) are decorated
with similar printf attributes (to force the same checks upon the
caller) - see
https://clang.llvm.org/docs/AttributeReference.html#format
for reference.

Adding these attributes revealed one existing mismatched format string
(fixed in the preceding commit).
2020-04-27 16:26:04 +03:00
Martin Storsjö
5ed1e39865 gregistrysettings: Fix a mismatched error format string 2020-04-27 16:26:04 +03:00
Martin Storsjö
4cf4dbfc1e meson: Add -Wno-format-zero-length for gcc/clang builds
Zero length format strings isn't something that needs to be warned
about.
2020-04-27 16:26:04 +03:00
Martin Storsjö
fcc7489d46 meson: Fix the gnulib checks for isnan* functions
The gnulib math code uses __builtin_isnanf and __builtin_isnanl
within the __GNUC__ >= 4 ifdef, and clang doesn't provide those
builtins, only the one without a suffix. Make the meson check
match the code it controls, using the exactly right builtins.

Set REPLACE_ISNAN to 1 if either of the have_isnan* functions failed,
this matches how gnulib's m4 routines does it (in gnulib/m4/isnan.m4).

This fixes the isnan functions in the gnulib math header replacement
work on Clang.
2020-04-25 22:16:10 +03:00
Ross Burton
2709d5e1bb gio/tests/memory-monitor-*.py.in: skip if 3rd party modules not available
The GIO tests memory-monitor-dbus and memory-monitor-portal use a number
of third party Python modules that may not be present when running the
test case.

Instead of failing due to missing imports, catch the ImportError and
mock a test case that skips.  This can't use the usual unittest.skip
logic because the test case class itself uses a 3rd party module.

Closes #2083.
2020-04-23 15:01:25 +01:00
Philip Withnall
de8708cd95 Merge branch 'wip/oholy/fast-content-type' into 'master'
gfile: Fallback to fast-content-type if content-type is not set

See merge request GNOME/glib!1442
2020-04-14 15:48:43 +00:00
Philip Withnall
fa76bde252 Merge branch 'tap' into 'master'
gio: use TAPTestRunner in the memory monitor tests

See merge request GNOME/glib!1443
2020-04-09 14:33:09 +00:00
Philip Withnall
0f8399fe2c Merge branch 'checks-asserts' into 'master'
Meson: Add glib-checks and glib-asserts options

See merge request GNOME/glib!1444
2020-04-09 14:09:13 +00:00
Ross Burton
1fcd32a159 gio: use TAPTestRunner in the memory monitor tests
There are two memory monitor tests that use Python's unittest module directly,
but GLib tests should be outputting TAP.  Use the embedded TAPTestRunner to
ensure that TAP is output for these tests too.
2020-04-09 14:55:39 +01:00
Xavier Claessens
be3728b9fa Meson: Add glib_checks and glib_asserts options
In cases where performance are critical it can be useful to disable
checks and asserts. GStreamer has those options too, using the same name
and setting them yielding means we can set those options on the main
project (e.g. gst-build) and glib will inherit the same value when built
as subproject.
2020-04-09 09:17:35 -04:00
Sebastian Dröge
12d79a3f7a Merge branch 'update-gvdb' into 'master'
Update gvdb

Closes #2

See merge request GNOME/glib!1446
2020-04-09 12:43:15 +00:00
Philip Withnall
683cf4c642 Merge remote-tracking branch 'gvdb/master' into update-gvdb
Bring in uninitialised memory fixes from
https://gitlab.gnome.org/GNOME/gvdb/issues/2.
2020-04-09 13:10:30 +01:00
Philip Withnall
82a557502d Merge branch '1841-cancellable-race-fix' into 'master'
Resolve "Signal handler disconnection race when finalising GCancellableSource"

Closes #1841

See merge request GNOME/glib!1400
2020-04-09 12:00:52 +00:00
Philip Withnall
bd45f71abb Merge branch 'override-dependency' into 'master'
Meson: Override every dependency glib provides

See merge request GNOME/glib!1441
2020-04-09 11:51:46 +00:00
Philip Withnall
6e3b1e069d gdatetime: Document that specific AM/PM formatting is discouraged
Many locales have no concept of AM/PM notation, and it’s confusing to
them. It’s an Anglo-centric concept which doesn’t belong in the API at
this level — instead, programs should use more generic format specifiers
which leave the details of how to format a date/time to the locale.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #2082
2020-04-09 12:26:12 +01:00
Ondrej Holy
461052f66e gfile: Fallback to fast-content-type if content-type is not set
The G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE attribute doesn't have to be
always set. See https://gitlab.gnome.org/GNOME/gvfs/-/merge_requests/68
for more details. In that case, the g_file_query_default_handler function
fails with the "No application is registered as handling this file" error.
Let's fallback to the "standard::fast-content-type" attribute instead to
fix issues when opening such files.

https://gitlab.gnome.org/GNOME/nautilus/-/issues/1425
2020-04-07 14:56:49 +02:00
Xavier Claessens
10280deebd Meson: Override every dependency glib provides
Meson 0.54.0 added a new method meson.override_dependency() that must be
used to ensure dependency consistency. This patch ensures a project that
depends on glib will never link to a mix of system and subproject
libraries. It would happen in such cases:

The system has glib 2.40 installed, and a project does:
dependency('glib-2.0', version: '>=2.60',
  fallback: ['glib', 'glib_dep'])
dependency('gobject-2.0')

The first call will configure glib subproject because the system libglib
is too old, but the 2nd call will return system libgobject.

By overriding 'gobject-2.0' dependency while configuring glib subproject
during the first call, meson knows that on the 2nd call it must return
the subproject dependency instead of system dependency.

This also has the nice side effect that with Meson >0.54.0 an
application depending on glib can declare the fallback without knowing
the dependency variable name: dependency('glib-2.0', fallback: 'glib').
2020-04-05 00:34:04 -04:00
Philip Withnall
1a3a1865eb Merge branch 'gmarkup-more-unit-tests' into 'master'
gmarkup tests: tab character escape/unescape

See merge request GNOME/glib!1437
2020-04-03 19:16:42 +00:00
Sebastian Dröge
a136776e81 Merge branch 'wip/oholy/gio-tool-docs' into 'master'
docs: Mention new gio tool options

See merge request GNOME/glib!1432
2020-04-03 15:03:05 +00:00
Sébastien Wilmet
50a3064933 gmarkup tests: tab character escape/unescape
"\t" is not escaped by g_markup_escape_text(), as per its documentation:

"Note that this function doesn't protect whitespace and line endings
from being processed according to the XML rules for normalization of
line endings and attribute values."

The relevant portion of the XML specification
https://www.w3.org/TR/xml/#AVNormalize

"For a character reference, append the referenced character to the
normalized value."
"For a white space character (#x20, #xD, #xA, #x9), append a space
character (#x20) to the normalized value."

So the unescape code in GMarkup does the right thing as can be verified
by the added valid-17.* data files for the markup-parse unit test.

(Note that the valid-13.* data files already tested a plain tab
character in an attribute value, among other white space characters).

Note that the libxml2's xmlSetProp() function escapes "\t" into the
character reference "&#9;".

See https://gitlab.gnome.org/GNOME/glib/-/issues/2080
2020-04-03 16:30:27 +02:00
Sebastian Dröge
4530aac317 Merge branch 'sync-valgrind' into 'master'
glib: Update internal copy of valgrind.h from Valgrind 3.15 release

See merge request GNOME/glib!1436
2020-04-03 13:12:36 +00:00
Sebastian Dröge
dde780fd1b Merge branch '2081-dbus-error-messages' into 'master'
gdbusmessage: Fix swapped signatures in error messages

Closes #2081

See merge request GNOME/glib!1435
2020-04-03 12:35:58 +00:00
Sebastian Dröge
5a540c8bca Merge branch 'dbus-signal-sender-nullability' into 'master'
gdbusconnection: Clarify nullability of SignalInstance.sender

See merge request GNOME/glib!1434
2020-04-03 12:11:58 +00:00
Philip Withnall
f07e5f6d08 glib: Update internal copy of valgrind.h from Valgrind 3.15 release
Update our copy of valgrind.h from the Valgrind 3.15 release tarball,
and then re-apply our downstream change af0e0cb995. No other
changes made.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-04-03 13:03:31 +01:00
Sebastian Dröge
87cd6a4a19 Merge branch 'fix-buildtype-usage' into 'master'
meson: Fix buildtype usage

See merge request GNOME/glib!1433
2020-04-03 11:58:56 +00:00