21650 Commits

Author SHA1 Message Date
Sebastian Dröge
d0e54ef794 Merge branch 'backport-1544-spawn-async-signal-safety-glib-2-64' into 'glib-2-64'
Backport !1544 “Resolve "calling malloc in fork child is undefined-behaviour"” to glib-2-64

See merge request GNOME/glib!1547
2020-06-24 11:58:49 +00:00
Philip Withnall
f99f0c2fab gspawn: Don’t use malloc() when running a binary under /bin/sh
Allocate a working buffer before calling `fork()` to avoid calling
`malloc()` in the async-signal-safe context between `fork()` and
`exec()`, where it’s not safe to use.

In this case, the buffer is used to assemble a wrapper around `argv` so
it can be run under `/bin/sh`.

See `man 7 signal-safety`.

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

Fixes: #2140
2020-06-24 11:40:22 +01:00
Philip Withnall
cc8715c3b7 gspawn: Don’t use malloc() when searching for a binary
Allocate a working buffer before calling `fork()` to avoid calling
`malloc()` in the async-signal-safe context between `fork()` and
`exec()`, where it’s not safe to use.

In this case, the buffer is used to assemble elements from `PATH` with
the binary from `argv[0]` to try executing them.

See `man 7 signal-safety`.

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

Helps: #2140
2020-06-24 11:40:22 +01:00
Philip Withnall
3548996c0e gspawn: Don’t use getenv() in async-signal-safe context
Query the environment before calling `fork()` so that it doesn’t have to
be called in the async-signal-safe context between `fork()` and
`exec()`.

See `man 7 signal-safety`.

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

Helps: #2140
2020-06-24 11:40:22 +01:00
Philip Withnall
45b8e60ac4 gspawn: Don’t use getrlimit() or sysconf() in async-signal-safe context
They’re not safe to call in an async-signal-safe context on Linux.
`sysconf()` is safe to call on FreeBSD and OpenBSD (at least), so
continue doing that.

This will reduce performance in the (already low performance) fallback
case where `/proc` is inaccessible to a forked process on Linux, while
spawning a subprocess.

See `man 7 signal-safety`.

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

Helps: #2140
2020-06-24 11:40:21 +01:00
Philip Withnall
923315ef82 gspawn: Don’t use g_assert() in async-signal-safe context
Use the error handling infrastructure which already exists for other
failures in the async-signal-safe context.

`g_assert()` is unlikely to have caused problems in practice because it
is only async-signal-unsafe when the assertion condition fails.

See `man 7 signal-safety`.

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

Helps: #2140
2020-06-24 11:40:21 +01:00
Philip Withnall
d24acc7ea5 gspawn: Don’t use g_ascii_isdigit() in async-signal-safe context
While `g_ascii_isdigit()` *is* currently async-signal-safe, it’s going
to be hard to remember to keep it that way if the implementation changes
in future.

It seems more robust to just reimplement it here, given that it’s not
much code.

See `man 7 signal-safety`.

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

Helps: #2140
2020-06-24 11:40:21 +01:00
Philip Withnall
539d51836a gspawn: Don’t use g_close() in async-signal-safe context
Use normal `close()` instead, which is guaranteed to be
async-signal-safe.

See `man 7 signal-safety`.

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

Helps: #2140
2020-06-24 11:40:21 +01:00
Philip Withnall
92eac2f424 gspawn: Audit for async-signal-safety
Functions called between `fork()` and `exec()` have to be
async-signal-safe.

Add a comment to each function which is called in that context, and
`FIXME` comments to the non-async-signal-safe functions which end up
being called as leaves of the call graph.

The following commits will fix those `FIXME`s.

See `man 7 signal-safety`.

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

Helps: #2140
2020-06-24 11:40:21 +01:00
Philip Withnall
aae98ce774 tree: Fix various ableist language
In almost all cases, rewording the documentation/comments made things
more specific and a little clearer.

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

See: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1544#note_846645
2020-06-24 11:40:21 +01:00
Matej Urbančič
4abdd10e48 Updated Slovenian translation 2020-06-22 21:00:31 +02:00
Nirbheek Chauhan
175b7e2727 Merge branch 'backport-1522-meson-printf-checks-glib-2-64' into 'glib-2-64'
Backport !1522 “meson: Fix gnulib printf checks” to glib-2-64

See merge request GNOME/glib!1523
2020-06-09 04:00:23 +00:00
Nirbheek Chauhan
d8d5664ba9 meson: Fix gnulib printf checks
Some typos, and accidental usage of the strings `'true'` / `'false'`
instead of the booleans `true` / `false`.
2020-06-08 15:20:00 +01:00
Руслан Ижбулатов
98570e2d69 GWin32RegistryKey: Move assertions
While these assertions look right at the first glance,
they actually crash the program. That's because GObject
insists on initializing all construct-only properties
to their default values, which results in
g_win32_registry_key_set_property() being called multiple
times with NULL string, once for each unset property.

If "path" is actually set by the caller, a subsequent
call to set "path-utf16" to NULL will fail an assertion,
since absolute_path is already non-NULL.

With assertions moved the set-to-NULL calls bail out before
an assertion is made.
2020-06-05 12:47:26 +01:00
Chun-wei Fan
e56a2865cb glib-compile-resources: Fix exporting on Visual Studio
Have the generated .c code decorate the prototypes with "G_MODULE_EXPORT"
instead of "extern" when --internal is not being used, so that we also
export the symbols from the generated code on Visual Studio-style
compilers.  If --internal is used, we decorate the prototypes with
"G_GNUC_INTERNAL", as we did before.

Note that since the generated .c code does not attempt to include the
generated headers (if one is also generated), the gnerated headers are
still generated as they were before.
2020-06-05 11:58:47 +01:00
Sebastian Dröge
2068a6c484 Merge branch 'backport-1504-win32-poll-glib-2-64' into 'glib-2-64'
Backport !1504 “win32 gpoll: Fix wait for at least one thread to return” to glib-2-64

See merge request GNOME/glib!1507
2020-05-22 10:32:16 +00:00
majordaw
66b56ee9d8 win32 gpoll: Fix wait for at least one thread to return
When timeout grater than 0 in g_poll function, the WaitForMultipleObjects
call will wait for all the threads to return, but when only one thread
got an event the others will sleep until the timeout elapses, and causes
a stall. Triggering the stop event in g_poll in this case is useless as
it is triggered when all the threads where already signaled or timed-out.

Closes: https://gitlab.gnome.org/GNOME/glib/issues/2107
2020-05-22 09:15:47 +01:00
Philip Withnall
af1edc1c33 2.64.3
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2.64.3
2020-05-20 11:45:25 +01:00
Philip Withnall
f39b885c0b Merge branch 'backport-1493-meson-typo-glib-2-64' into 'glib-2-64'
Backport !1493 “meson: Remove stray ], in O_DIRECTORY check” to glib-2-64

See merge request GNOME/glib!1495
2020-05-19 16:48:33 +00:00
Chris Packham
15e73829aa meson: Remove stray ], in O_DIRECTORY check
A stray ], was leftover from the autotools -> meson conversion. Remove
it.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
2020-05-19 16:35:06 +01:00
Sebastian Dröge
50ccd7b714 Merge branch 'backport-1439-stpcpy-fix-glib-2-64' into 'glib-2-64'
Backport !1439 “Fix stpcpy() detection“ to glib-2-64

See merge request GNOME/glib!1501
2020-05-19 15:29:12 +00:00
Martin Storsjö
3c5512222c meson: Don't misdetect stpcpy on windows platforms on clang
See https://github.com/mesonbuild/meson/issues/3672 and
https://github.com/mesonbuild/meson/issues/5628 for explanations
of cases where meson misdetects functions due to clang builtins (that
always are available, regardless of whether the platform actually
provides them).

The same also happens on GCC 10, which added support for __has_builtin.
2020-05-19 15:46:45 +01:00
Cheng-Chia Tseng
c49ee9efbd Update Chinese (Taiwan) translation 2020-05-17 17:11:02 +00:00
Cheng-Chia Tseng
d06de90330 Update Chinese (Taiwan) translation 2020-05-17 17:00:33 +00:00
Cheng-Chia Tseng
e55f6a95b5 Update Chinese (Taiwan) translation 2020-05-17 16:54:18 +00:00
Emmanuele Bassi
624e18f0fb Merge branch 'backport-1440-format-nonliteral-glib-2-64' into 'glib-2-64'
Backport !1440 -Wformat-nonliteral fixes to glib-2-64

See merge request GNOME/glib!1470
2020-05-14 14:08:27 +00:00
Emmanuele Bassi
46756977a1 Merge branch 'backport-1448-dbus-tests-glib-2-64' into 'glib-2-64'
Backport !1448 memory monitor test dependency fixes to glib-2-64

See merge request GNOME/glib!1471
2020-05-14 14:06:55 +00:00
Emmanuele Bassi
b53de16538 Merge branch 'backport-1481-ptr-array-corruption-fix' into 'glib-2-64'
Backport !1481 “array: fix corrupt state of GPtrArray after g_ptr_array_extend_and_steal()” to glib-2-64

See merge request GNOME/glib!1483
2020-05-14 14:06:14 +00:00
Emmanuele Bassi
f66e56bc2b Merge branch 'backport-1472-thread-deprecation-warnings-glib-2-64' into 'glib-2-64'
Backport !1472 “gthread: ignore deprecated declarations in static inline functions” to glib-2-64

See merge request GNOME/glib!1486
2020-05-14 14:05:12 +00:00
Simon Marchi
5ee80104ac 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-07 11:10:21 +01:00
Christoph Reiter
b715f7535a Merge branch 'backport-1480-msys2-ci-fix-glib-2-64' into 'glib-2-64'
Backport !1480 “CI: Make sure we use meson 0.49.2 in MSYS2” to glib-2-64

See merge request GNOME/glib!1484
2020-05-07 09:48:18 +00:00
Christoph Reiter
857a91833c CI: Make sure we use meson 0.49.2 in MSYS2
pip in MSYS2 seems to install scripts into $USERPROFILE instead of $HOME
which means the MSYS2 meson, which is newer, wins. Make sure $USERPROFILE
is in PATH as well.
2020-05-07 09:48:49 +01:00
Thomas Haller
ebc518da45 array: fix corrupt state of GPtrArray after g_ptr_array_extend_and_steal()
g_ptr_array_extend_and_steal() leaves the GPtrArray in an invalid state,
so if you would try to append another pointer, it leads to a crash.

Also adjust the test case so that it would result in the crash (without
the fix).

Fixes: 0675703af08d ('Adding g_ptr_array_extend_and_steal() function to glib/garray.c')
2020-05-07 09:44:40 +01:00
Simon McVittie
d020a73b66 Merge branch 'backport-1477-dbus-keyring-handling-glib-2-64' into 'glib-2-64'
Backport !1477 D-Bus keyring handling fixes to glib-2-64

See merge request GNOME/glib!1478
2020-05-05 18:46:28 +00:00
Philip Withnall
f3b6700256 gdbusauthmechanismsha1: Reduce syscalls from ensure_keyring_directory()
There’s no need to call `access()` and then `stat()` on the keyring
directory to check that it exists, is a directory, and has the right
permissions. Just call `stat()`.

This eliminates one potential TOCTTOU race in this code.

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

Helps: #1954
2020-05-05 17:46:31 +01:00
Philip Withnall
b4664e237a 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 17:46:31 +01:00
Philip Withnall
a0689d21e4 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 17:46:31 +01:00
Philip Withnall
d20664c6d4 gdbusauthmechanismsha1: Fix return type in precondition guards
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-05-05 17:46:31 +01:00
Philip Withnall
1a35d27f1b 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 17:46:31 +01:00
Philip Withnall
de0fae3d49 tests: Fix a memory leak in gdbus-server-auth
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-05-05 17:46:31 +01:00
Philip Withnall
95f6d3c808 Merge branch 'windows-ci-switch-2-64' into 'glib-2-64'
CI: Switch to new Windows runners (2.64)

See merge request GNOME/glib!1473
2020-05-04 09:23:40 +00:00
Christoph Reiter
c8f6aab8b2 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-05-02 13:16:48 +02:00
Ross Burton
f11fd52dd2 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-05-01 18:06:31 +01:00
Ross Burton
5903b75185 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-05-01 18:06:31 +01:00
Martin Storsjö
693013bba5 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-05-01 17:59:33 +01:00
Martin Storsjö
8d7b170656 gregistrysettings: Fix a mismatched error format string 2020-05-01 17:59:33 +01:00
Martin Storsjö
43c826021a meson: Add -Wno-format-zero-length for gcc/clang builds
Zero length format strings isn't something that needs to be warned
about.
2020-05-01 17:59:33 +01:00
Christian Kirbach
acefe859e6 Update German translation 2020-04-14 13:33:57 +00:00
Philip Withnall
e264e6fcf7 2.64.2
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2.64.2
2020-04-09 14:40:24 +01:00
Sebastian Dröge
6bebadace6 Merge branch 'backport-1442-gfile-content-type-glib-2-64' into 'glib-2-64'
Backport !1442 “gfile: Fallback to fast-content-type if content-type is not set” to glib-2-64

See merge request GNOME/glib!1447
2020-04-09 13:16:38 +00:00