Commit Graph

21285 Commits

Author SHA1 Message Date
Sebastian Dröge
f904587fcc Merge branch 'locale-docs' into 'master'
gcharset: Expand the documentation for g_get_locale_variants()

See merge request GNOME/glib!1163
2019-10-18 14:38:36 +00:00
Sebastian Dröge
51c3cf759e Merge branch 'timezone-test-toolbox' into 'master'
Fix gdatetime tests on toolbox

See merge request GNOME/glib!1168
2019-10-18 14:34:07 +00:00
Sebastian Dröge
bab6acff9b Merge branch 'atomic-strict-aliasing-fixes' into 'master'
Strict-aliasing fixes to new atomic built-ins

See merge request GNOME/glib!1155
2019-10-18 14:00:26 +00:00
Philip Withnall
25c2266a33 gvariant: Limit recursion in g_variant_parse()
The token parsing done by g_variant_parse() uses recursive function
calls, so at some point it will hit the stack limit. As with previous
changes to `GVariantType` parsing (commit 7c4e6e9fbe), limit the level
of nesting of containers parsed by g_variant_parse() to something
reasonable. We guarantee 64 levels of nesting, which should be enough
for anyone, and is the same as what we guarantee for types.

oss-fuzz#10286

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-10-18 13:53:18 +01:00
Will Thompson
43697d6b99 Revert "gdbus-codegen: emit GUnixFDLists if an arg has type 'h'"
This reverts commit 4aba03562b, preserving
the new tests but adjusting them to assert that the old behaviour is
restored.

As expected, there were a few projects which broke because of this.
Unfortunately, in one case the breakage crosses a project boundary:
sysprof ships D-Bus introspection XML, which is consumed by mutter and
passed through gdbus-codegen.

Since sysprof cannot add this annotation without breaking its existing
users, a warning is also not appropriate.

https://gitlab.gnome.org/GNOME/jhbuild/issues/41
https://gitlab.gnome.org/GNOME/sysprof/issues/17
https://gitlab.gnome.org/GNOME/glib/issues/1726
2019-10-18 10:30:00 +01:00
Philip Withnall
5dedc259b1 gtimezone: Clarify in docs that TZ can contain an absolute path
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-10-16 14:32:33 +01:00
Philip Withnall
c4d46d632f tests: Relax the time zone identifier tests
On closer reading of `man 3 timezone`, it’s actually permissible for
`TZ` to contain an absolute path which points to a tzfile file outside
the system time zone database. This is indeed what happens when building
GLib under Fedora’s toolbox, so relax that check in the tests.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-10-16 14:32:20 +01:00
Philip Withnall
3dec72b946 Merge branch 'wip/lantw/use-uname-as-a-fallback-to-get-os-info' into 'master'
Use uname as a fallback to get OS info

See merge request GNOME/glib!1165
2019-10-14 13:10:39 +00:00
Ting-Wei Lan
d219b3553c gutils: Use uname to report OS info when there is no os-release file
There are a lot of Unix-like systems which have not implemented the
os-release spec. On such system, we can use POSIX uname function as a
fallback to get basic information of the system.
2019-10-14 13:42:08 +01:00
Ting-Wei Lan
00abf67e2c gutils: Only use the default OS name on Linux
/etc/os-release is a spec designed for Linux. While other OSes can
implement it, it doesn't make sense to use Linux as the default value
on systems which don't use Linux.
2019-10-14 20:25:51 +08:00
Ting-Wei Lan
89ad9286d4 gutils: Do not translate OS names
The code is intended to provide an interface similar to /etc/os-release,
but /etc/os-release isn't designed to be translated.
2019-10-14 20:25:51 +08:00
Philip Withnall
493909b5e9 Merge branch 'osinfo' into 'master'
Add Windows support to g_get_os_info()

See merge request GNOME/glib!1160
2019-10-14 12:12:06 +00:00
Philip Withnall
592a13b483 glocalfilemonitor: Keep a weak ref to the monitor in GFileMonitorSource
Previously we were keeping a pointer to the `GFileMonitor` in a
`GFileMonitorSource` instance, but since we weren’t keeping a strong
reference, that `GFileMonitor` instance could be finalised from another
thread at any point while the source was referring to it. Not good.

Use a weak reference, and upgrade it to a strong reference whenever the
`GFileMonitorSource` is referring to the file monitor.

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

Helps: #1903
2019-10-11 22:31:24 +01:00
Philip Withnall
5b07fc98e0 gdesktopappinfo: Cancel file monitor when resetting a DesktopFileDir
It’s not enough to unref the monitor, since the GLib worker thread might
still hold a reference to it.

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

Helps: #1903
2019-10-11 22:31:24 +01:00
Philip Withnall
bffe058550 gdesktopappinfo: Allocate DesktopFileDir structs dynamically
`DesktopFileDir` pointers are passed around between threads: they are
initially created on the main thread, but a pointer to them is passed to
the GLib worker thread in the file monitor callback
(`desktop_file_dir_changed()`).

Accordingly, the `DesktopFileDir` objects either have to be
 (1) immutable;
 (2) reference counted; or
 (3) synchronised between the two threads
to avoid one of them being used by one thread after being freed on
another. Option (1) changed with commit 99bc33b6 and is no longer an
option. Option (3) would mean blocking the main thread on the worker
thread, which would be hard to achieve and is against the point of
having a worker thread. So that leaves option (2), which is implemented
here.

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

Fixes: #1903
2019-10-11 22:31:24 +01:00
Philip Withnall
cea8424e80 gcharset: Expand the documentation for g_get_locale_variants()
Include some more examples, and a reference to the format of locales.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-10-11 11:47:42 +01:00
Руслан Ижбулатов
fc2f566a98 Add Windows support to g_get_os_info()
Most of the info returned is static, the only thing that changes
is the OS version.

This code relies on g_win32_check_windows_version() providing
accurate information (hopefully, MS won't nix RtlGetVersion() on
which we use for that) and supplements it with information from the
registry for Windows >= 8.1.
2019-10-11 06:07:26 +00:00
Philip Withnall
c7dd1ae040 Merge branch '1896-use-after-free-when-calling-g_dbus_connection_flush_sync-in-a-dedicated-thread' into 'master'
Resolve "Use after free when calling g_dbus_connection_flush_sync() in a dedicated thread"

Closes #1896

See merge request GNOME/glib!1158
2019-10-10 14:55:20 +00:00
Milan Crha
822f8bae9e Fix use-after-free when calling g_dbus_connection_flush_sync()
When the _g_dbus_worker_flush_sync() schedules the 'data' and releases
the worker->write_lock, it is possible for the GDBus worker thread thread
to finish the D-Bus call and acquire the worker->write_lock before
the _g_dbus_worker_flush_sync() re-acquires it in the if (data != NULL) body.
When that happens, the ostream_flush_cb() increases the worker->write_num_messages_flushed
and then releases the worker->write_lock. The write lock is reacquired by
the _g_dbus_worker_flush_sync(), which sees that the while condition is satisfied,
thus it doesn't enter the loop body and immediately clears the data members and
frees the data structure itself. The ostream_flush_cb() is still ongoing, possibly
inside flush_data_list_complete(), where it accesses the FlushData, which can be
in any stage of being freed.

Instead, add an explicit boolean flag indicating when the flush is truly finished.

Closes #1896
2019-10-10 14:55:20 +00:00
Philip Withnall
c97565748a Merge branch 'wip/tingping/localhost-is-local' into 'master'
Always resolve localhost to loopback address

See merge request GNOME/glib!616
2019-10-10 14:53:42 +00:00
Philip Withnall
a50a08fd5e Merge branch 'datetime-docs' into 'master'
gdatetime: Document RFC 3339 extensions when parsing ISO 8601

See merge request GNOME/glib!1082
2019-10-10 14:06:13 +00:00
Philip Withnall
ea98aab57b gdatetime: Document RFC 3339 extensions when parsing ISO 8601
This is a follow-up to !1017.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-10-10 14:06:13 +00:00
Philip Withnall
168bdb11ca Merge branch 'hash-me-faster' into 'master'
hash: Remove an assertion from the hot path

See merge request GNOME/glib!1161
2019-10-10 14:01:21 +00:00
Patrick Griffis
ea99872e45 Always resolve localhost to loopback address
This always resolves "localhost" to a loopback address which
has security benefits such as preventing a malicious dns server
redirecting local connections and allows software to assume
it is a secure hostname.

This is being adopted by web browsers:

- https://w3c.github.io/webappsec-secure-contexts/
- https://groups.google.com/a/chromium.org/forum/#!msg/blink-dev/RC9dSw-O3fE/E3_0XaT0BAAJ
- 8da2a80724
- https://bugs.webkit.org/show_bug.cgi?id=171934
- https://tools.ietf.org/html/draft-west-let-localhost-be-localhost-06
2019-10-10 14:32:18 +01:00
Patrick Griffis
01acb8907f tests: Don't block mainloop for delays in gnetworkaddress tests 2019-10-10 14:32:18 +01:00
Matthias Clasen
1fb3628fb3 hash: Remove an assertion from the hot path
This assert is using atomics and was showing up
in some cache-heavy GTK profiles. Remove it.
2019-10-10 14:24:42 +01:00
Philip Withnall
b50447b0ab Merge branch 'issue1906' into 'master'
gutils test: Don't assume that every Unix OS implements os-release(5)

Closes #1906

See merge request GNOME/glib!1159
2019-10-10 13:18:44 +00:00
Philip Withnall
0869cdedcf Merge branch '1858-tutorial-deprecated-gobject-api' into 'master'
Fix handling of private object members in GObject property tutorial

Closes #1858

See merge request GNOME/glib!1069
2019-10-10 13:15:39 +00:00
Daniel Mustieles
150b946974 Updated Spanish translation 2019-10-10 13:55:48 +02:00
Philip Withnall
d770e00d9c Merge branch 'wip/g-warning-once' into 'master'
gmessages: Add g_warning_once()

See merge request GNOME/glib!1028
2019-10-09 15:09:53 +00:00
Jonas Ådahl
15e3b6f136 gmessages: Add g_warning_once()
In many places the pattern

    static gboolean warned_once = FALSE;
    if (!warned_once)
      {
        g_warning ("This and that");
        warned_once = TRUE;
      }

is used to not spam the same warning message over and over again. Add a
helper in glib for this, allowing the above statement to be changed to

    g_warning_once ("This and that");
2019-10-09 16:39:31 +02:00
Simon McVittie
f9a1970a0f gutils test: Don't assume that every Unix OS implements os-release(5)
os-release(5) is widely implemented on Linux, but not necessarily
ubiquitous: unusual or minimal Linux distributions might not have it.
It could in principle be implemented by any other Unix OS, but in
practice this has not yet happened.

Closes: https://gitlab.gnome.org/GNOME/glib/issues/1906
Fixes: 349318e8 "gutils: Add g_get_os_info()"
Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-10-09 14:11:08 +01:00
Simon McVittie
35e26151a8 Merge branch 'android-warning-fixes' into 'master'
Fix various compiler warnings on Android

See merge request GNOME/glib!1157
2019-10-09 12:33:00 +00:00
Philip Withnall
8492df9f34 gdbusaddress: Validate the noncefile attribute of nonce-tcp addresses
Doing this mostly to fix a compiler warning about tautological
assignments on Android.

See the D-Bus specification:
https://dbus.freedesktop.org/doc/dbus-specification.html#transports-nonce-tcp-sockets

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-10-08 13:53:01 +01:00
Philip Withnall
e99003841a gdbusaddress: Collapse two translatable strings into one
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-10-08 13:51:57 +01:00
Philip Withnall
3c4ff30c0f gunicollate: Remove tautological comparison
As an unsigned integer, this variable is always greater than or equal to
zero. Fixes a compiler warning on Android.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-10-08 13:50:13 +01:00
Philip Withnall
e257e17d2e inotify: Fix some enum comparisons to integers
`-1` isn’t a valid member of the enum, so cast to `int` first. This
fixes a compiler warning on Android.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-10-08 13:49:40 +01:00
Philip Withnall
30dd30d05a tests: Remove redundant old atomic test
The test in `glib/tests/atomic.c` does everything this test did, and
more.

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

Helps: #1434
2019-10-08 12:10:20 +01:00
Philip Withnall
5dbaa18d61 tests: Test g_atomic_pointer_compare_and_exchange() returning false
There were tests for the situation where it does the exchange and
returns true, but no tests for the situation where it returns false.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-10-08 12:10:20 +01:00
Ting-Wei Lan
1bda4db213 Update Chinese (Taiwan) translation 2019-10-08 10:45:43 +00:00
Philip Withnall
0d94ee3bb4 Merge branch 'master' into 'master'
Erase GI annotation: skip g_cancellable_source_new

Closes #1877

See merge request GNOME/glib!1048
2019-10-08 10:33:40 +00:00
Philip Withnall
45c91d7ed6 Merge branch 'g-os-info' into 'master'
gutils: Add g_get_os_info()

See merge request GNOME/glib!1063
2019-10-08 10:30:24 +00:00
Philip Withnall
ab613ae805 Merge branch '1726-gdbus-codegen-h' into 'master'
Resolve "Warn when method/signal uses type 'h' but lacks GDBus.C.UnixFD annotation"

Closes #1726

See merge request GNOME/glib!1079
2019-10-08 10:26:45 +00:00
Philip Withnall
b229eed0e4 Merge branch 'str-printf-abort-oom' into 'master'
Ensure that g_vasprintf will always abort on OOM and some docs fixes

Closes #1622

See merge request GNOME/glib!1145
2019-10-07 17:21:32 +00:00
Daniel P. Berrangé
109be1e90d glib: add parameter annotations for g_vasprintf and callers
Document that g_vasprintf and g_strdup_printf are guaranteed to return a
non-NULL string, unless the format string contains the locale sensitive
conversions %lc or %ls.

Further annotate that the output parameter for g_vasprintf and the
format string for all functions must be non-NULL.

Fixes #1622

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-10-07 17:29:34 +01:00
Daniel P. Berrangé
14035010dd glib: ensure consistent abort-on-OOM with g_vasprintf & its callers
The g_vasprintf method is called by g_strdup_vprintf, g_strdup_printf,
g_string_append_vprintf and more. It has three different implementations
depending on what the build target platform supports:

  1. The gnulib impl appears to use the system malloc, but a
     '#define malloc g_malloc' causes it to use GLib's wrapper
     and thus abort on OOM. This mostly gets used on Windows
     platforms or UNIX platforms with broken printf formatting.

  2. The main impl mostly used on modern Linux/UNIX calls the
     system vasprintf which uses the system malloc and does not
     abort on OOM.

  3. The final impl used on remaining platforms calls system
     vsprintf on a buffer allocated by g_new, and thus always
     aborts on OOM.

Of note is that impl 2 (using vasprintf) historically could abort on
OOM, if the application had installed a non-system malloc impl with
GLib. This was because the code would g_strndup the result from
vasprintf() in that scenario. This was removed in:

  commit a366053253
  Author: Dan Winship <danw@gnome.org>
  Date:   Fri Aug 7 09:46:49 2015 -0400

    glib: remove deprecated g_mem_is_system_malloc() check in gprintf.c

Having inconsistent OOM behaviour for the three impls is undesirable and
aborting on OOM is normal pratice for GLib APIs. Thus we must thus ensure
this happens in all impls of g_vasprintf.

Fixes #1622

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-10-07 17:29:29 +01:00
Philip Withnall
d9b30d47a6 gmain: Remove some redundant casts
These were introducing strict aliasing warnings. Remove them (in line
with other uses of `g_once_init_leave()`).

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-10-07 16:29:26 +01:00
Philip Withnall
3251cce524 gatomic: Fix strict aliasing problems with g_atomic_pointer_{get,set}()
Casting pointer types around is a bit fiddly when you also end up
dereferencing them. Take advantage of the fact that the
`__atomic_load()` and `__atomic_store()` built-ins are polymorphic, and
use `__typeof__()` to ensure that the atomic pointer macros use the
caller-provided types internally, and hence any type mismatches are
entirely the caller’s fault rather than ours.

This also means that the `__atomic_{load,store}()` built-ins have the
right alignment and width data from the caller-provided types, in case
that’s needed.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-10-07 16:23:02 +01:00
Philip Withnall
81f8d02e4d glib: Various fixes to the return type of atomic functions
Various places that used atomic functions were using the wrong return
type. Fix that. This introduces no functional changes.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-10-07 16:21:24 +01:00
Philip Withnall
4e12e7ed0d Merge branch 'th/main-context-default-no-mutex' into 'master'
gmain: use atomic operation instead of GMutex to access g_main_context_default()

See merge request GNOME/glib!1135
2019-10-07 13:22:30 +00:00