Commit Graph

7207 Commits

Author SHA1 Message Date
Andy Fiddaman
1fafbb82b0 Include glibconfig.h to get the G_OS_UNIX token 2021-03-18 16:21:42 +00:00
Simon McVittie
1248b642ad gversionmacros: Add version macros for GLib 2.70
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-03-18 13:58:41 +00:00
Michael Catanzaro
3a74ad128e tests: Fix copy/paste error in queue test
Coverity is pretty good at detecting copy/paste errors.
2021-03-16 12:53:44 -05:00
Philip Withnall
c92d9dc267 enums: Add missing GLIB_AVAILABLE_ENUMERATOR_IN_2_68 annotations
In the 2.68 cycle we’d added 3 new enumerator elements. Due to the
preceding commit, they can now be annotated with
`GLIB_AVAILABLE_ENUMERATOR_IN_2_68`, which will make it a bit easier for
third party projects to notice when they’re using these symbols without
having bumped their GLib dependency.

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

Fixes: #2327
2021-03-11 13:37:49 +00:00
Aleksandr Mezin
d18bdef42d gbitlock.c: replace remaining 'asm' with '__asm__'
Commit 2330f7e65e changed 'asm' to '__asm__' in
g_bit_lock and g_bit_trylock.

Replace 'asm' with '__asm__' in the remaining functions.

Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/2344
2021-03-04 04:39:27 +06:00
Philip Withnall
6cc6df230a Merge branch 'glib-typeof-gatomic-h' into 'master'
gatomic.h: Make `glib_typeof` API break opt in.

See merge request GNOME/glib!1975
2021-03-01 13:19:08 +00:00
Iain Lane
5b3e4f94b0
gatomic.h: Make glib_typeof API break opt in.
The changes in 4273c43902 did not guard
macros in `gatomic.h` which use `glib_typeof`. This meant that when
552b8fd862 was committed, moving the
include of `<type_traits>` under such a guard, these macros were still
trying to use it. This broke the build of at least vte.

Fix this by guarding the API break in `gatomic.h` too.
2021-03-01 09:18:03 +00:00
Olivier Brunel
ddb2b5fe54 GRWLock: Tweak doc to make things a bit clearer
The doc used different phrasing for the same thing, e.g. "if any thread"
vs "any other thread."

Also make it clear that trying to take a write lock while already having
a lock, or trying to take a read lock while having a write lock, is
undefined.
2021-02-27 20:34:30 +01:00
Iain Lane
552b8fd862
glib/gmacros.h: Move <type_traits> include to consumers
When included inside an `extern "C"` block, this causes build failures
that look something like:

  /usr/include/c++/10/type_traits:2930:3: error: template with C linkage
   2930 |   template<typename _Fn, typename... _Args>
        |   ^~~~~~~~
  ../../disas/arm-a64.cc:20:1: note: ‘extern "C"’ linkage started here
     20 | extern "C" {
        | ^~~~~~~~~~

Commit 4273c43902 made this opt in for
projects which are defining `GLIB_VERSION_MIN_REQUIRED`, but the include
of `<type_traits>` via `gmacros.h` was not included in this. If we move
the include out to the places where `glib_typeof` is called, we can make
it covered by this macro too, and save a few consumers from FTBFSing.

That also means that, if you don't want to fix your use of the headers,
and as long as this version is sufficient for you, a quick workaround is
to define `GLIB_VERSION_MIN_REQUIRED` to `GLIB_VERSION_2_66` or lower.

Suggested by Simon McVittie.

Alternative to: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1935
Fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/2331
2021-02-25 15:33:59 +00:00
Philip Withnall
b018730087 tests: Add missing NULL terminator to spawn-singlethread test
This should have been in commit
b31f3f5f80.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-02-16 15:08:47 +00:00
Philip Withnall
51e964849b Merge branch '2097-spawn-fd-rewriting' into 'master'
Resolve "GSubprocessLauncher with FD assignment can clash with g_spawn_async internal pipe"

Closes #2097

See merge request GNOME/glib!1690
2021-02-16 14:04:39 +00:00
Philip Withnall
eebb66280d gspawn-win32: Various minor internal const-correctness fixes
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-02-16 13:44:00 +00:00
Philip Withnall
ea9fd4c2f2 gspawn-win32: Implement g_spawn_async_with_pipes_and_fds()
The `source_fds`/`target_fds` functionality is not supported on Windows
at the moment.

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

Fixes: #2097
2021-02-16 13:44:00 +00:00
Philip Withnall
a34b674134 gspawn-win32: Refactor internal spawn functions
This should introduce no functional changes, but condenses the variants
of the internal spawn implementation down to be more like `gspawn.c`.

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

Helps: #2097
2021-02-16 13:44:00 +00:00
Philip Withnall
ba403908a2 gspawn-win32: Rename a variable for consistency with the public headers
I realise Windows uses handles rather than PIDs, but given that there
are multiple platform-specific implementations of the public
`g_spawn_*()` API, I think it is less confusing for them all to use the
same naming scheme.

This introduces no functional changes.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-02-16 13:44:00 +00:00
Philip Withnall
fd0b20d537 gspawn: Minor improvements to documentation formatting
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-02-16 13:44:00 +00:00
Philip Withnall
b31f3f5f80 gspawn: Add new g_spawn_async_with_pipes_and_fds() API
This is a simple wrapper around the new source/target FD mapping
functionality in `fork_exec()`.

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

Helps: #2097
2021-02-16 13:44:00 +00:00
Philip Withnall
52dc7cb9dd tests: Add setlocale() call to spawn-singlethread
This allows non-ASCII characters to be used in test messages from it.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-02-16 13:44:00 +00:00
Philip Withnall
c5f3ba7f01 gspawn: Avoid merged FDs being closed on exec()
If `stdout_fd` was set to (say) 6, and `stderr_fd` was set to 1, the
`set_cloexec()` call for setting up `stderr` would set the new `stdout`
for the forked process to be closed in the pending `exec()`.

This would cause the child process to error when writing to `stdout`.

This situation happens when using `G_SUBPROCESS_FLAGS_STDERR_MERGE`.

Add some conditions to prevent setting `CLOEXEC` in such cases.

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

Helps: #2097
2021-02-16 13:44:00 +00:00
Philip Withnall
f20f0d385e gspawn: Avoid custom FDs conflicting with the child_err_report_fd
It was previously possible to specify the FD number which
`child_err_report_fd` was assigned, as a target FD in the FD mapping set
up using `g_subprocess_launcher_take_fd()`.

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

Fixes: #2097
2021-02-16 13:44:00 +00:00
Philip Withnall
7be9767cc4 gspawn: Handle arbitrary FD passing and renumbering between fork/exec
This effectively moves some of the functionality of `GSubprocess`
(`g_subprocess_launcher_take_fd()`) into `g_spawn*()`, which should make
implementation a little simpler.

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

Helps: #2097
2021-02-16 13:44:00 +00:00
Philip Withnall
cddcd24b52 gspawn: Combine fork_exec() implementations
This is an internal change which won’t affect the public API. It should
introduce no functional changes, but simplifies the code a little.

The arguments from `fork_exec_with_pipes()` have been added to
`fork_exec_with_fds()`. `child_close_fds` has been dropped since it’s
now an implementation detail within the function.

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

Helps: #2097
2021-02-16 13:44:00 +00:00
Philip Withnall
58dd7a37c9 Merge branch 'wip/smcv/armel-atomic-pointer-get' into 'master'
gatomic: Make fallback g_atomic_pointer_get type-safe

See merge request GNOME/glib!1949
2021-02-15 21:47:41 +00:00
Philip Withnall
63467c559e gspawn: Remove spurious blank lines
This introduces no functional changes.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-02-15 12:28:56 +00:00
Philip Withnall
12a627be55 gspawn: Reindent some arguments
They were indented incorrectly and I’m about to add some additional
ones.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2021-02-15 12:28:56 +00:00
Philip Withnall
3dec1b2c00 Merge branch '2319-memdup-deprecation' into 'master'
gstrfuncs: Deprecate g_memdup() in favour of g_memdup2()

Closes #2319

See merge request GNOME/glib!1928
2021-02-15 12:19:31 +00:00
Simon McVittie
d2b4ba55cb gatomic: Make fallback g_atomic_pointer_get type-safe
Since !1715, g_atomic_pointer_get (&x) has usually returned the type of
x, rather than a generic pointer, in C++ code (where x is any pointer,
or any pointer-sized integer such as guintptr). glib/tests/cxx.cpp
asserts that this is the case.

However, this was only implemented for the lock-free fast-path, not
for the slow path used in platforms with an ARMv5 baseline (and
therefore no atomic instructions) such as Debian armel.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-02-14 23:38:35 +00:00
Matthias Clasen
5bad389e63 Add a test for parsing 0 as double
Add a test for #2329.
2021-02-13 14:41:44 -05:00
Krzesimir Nowak
acb7b0ec69 gbytearray: Do not accept too large byte arrays
GByteArray uses guint for storing the length of the byte array, but it
also has a constructor (g_byte_array_new_take) that takes length as a
gsize. gsize may be larger than guint (64 bits for gsize vs 32 bits
for guint). It is possible to call the function with a value greater
than G_MAXUINT, which will result in silent length truncation. This
may happen as a result of unreffing GBytes into GByteArray, so rather
be loud about it.

(Test case tweaked by Philip Withnall.)
2021-02-11 10:14:15 +00:00
Kjell Ahlstedt
e008301cf8 guniprop, glib/tests/unicode: Fix style issues 2021-02-10 18:25:53 +02:00
Kjell Ahlstedt
b9a4897900 guniprop: Fix g_utf8_strdown() for Turkish locale
In the Turkish locale the lowercase equivalent of a capital I with dot above
is a normal lowercase i with a dot above.

Fixes part of issue #390
2021-02-10 18:25:53 +02:00
Joshua Lee
c576a4cd82 string: Add find and replace function
This adds g_string_replace(), a function that replaces instances of one string
with another in a GString. It allows the caller to specify the maximum number
of replacements to perform, and returns the number of replacements performed
to the caller.

Fixes: #225
2021-02-09 10:50:16 +00:00
Simon McVittie
63f37f8c3b io-channel test: Add coverage for g_io_channel_set_line_term(., ., -1)
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-02-08 10:37:01 +00:00
Simon McVittie
5dc8b0014c giochannel: Don't store negative line_term_len in GIOChannel struct
Adding test coverage indicated that this was another bug in 0cc11f74.

Fixes: 0cc11f74 "giochannel: Forbid very long line terminator strings"
Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/2323
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-02-08 10:37:01 +00:00
Jan Alexander Steffens (heftig)
a149bf2f90
giochannel: Fix length_size bounds check
The inverted condition is an obvious error introduced by ecdf91400e.

Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/2323
2021-02-07 23:32:40 +01:00
Philip Withnall
feff097f27 gstrfuncs: Deprecate g_memdup() in favour of g_memdup2()
Unfortunately, `g_memdup()` accepts its size argument as a `guint`,
unlike most other functions which deal with memory sizes — they all use
`gsize`. `gsize` is 64 bits on 64-bit machines, while `guint` is only 32
bits. This can lead to a silent (with default compiler warnings)
truncation of the value provided by the caller. For large values, this
will result in the returned heap allocation being significantly smaller
than the caller expects, which will then lead to buffer overflow
reads/writes.

Any code using `g_memdup()` should immediately port to `g_memdup2()` and
check the pointer arithmetic around their call site to ensure there
aren’t other overflows.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Fixes: #2319
2021-02-04 17:34:03 +00:00
Philip Withnall
0cc11f745e giochannel: Forbid very long line terminator strings
The public API `GIOChannel.line_term_len` is only a `guint`. Ensure that
nul-terminated strings passed to `g_io_channel_set_line_term()` can’t
exceed that length. Use `g_memdup2()` to avoid a warning (`g_memdup()`
is due to be deprecated), but not to avoid a bug, since it’s also
limited to `G_MAXUINT`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Helps: #2319
2021-02-04 16:17:21 +00:00
Philip Withnall
19470722b3 glib: Use g_memdup2() instead of g_memdup() in obvious places
Convert all the call sites which use `g_memdup()`’s length argument
trivially (for example, by passing a `sizeof()` or an existing `gsize`
variable), so that they use `g_memdup2()` instead.

In almost all of these cases the use of `g_memdup()` would not have
caused problems, but it will soon be deprecated, so best port away from
it

In particular, this fixes an overflow within `g_bytes_new()`, identified
as GHSL-2021-045 by GHSL team member Kevin Backhouse.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Fixes: GHSL-2021-045
Helps: #2319
2021-02-04 16:04:10 +00:00
Philip Withnall
f8cf0b8672 gstrfuncs: Add g_memdup2() function
This will replace the existing `g_memdup()` function, which has an
unavoidable security flaw of taking its `byte_size` argument as a
`guint` rather than as a `gsize`. Most callers will expect it to be a
`gsize`, and may pass in large values which could silently be truncated,
resulting in an undersize allocation compared to what the caller
expects.

This could lead to a classic buffer overflow vulnerability for many
callers of `g_memdup()`.

`g_memdup2()`, in comparison, takes its `byte_size` as a `gsize`.

Spotted by Kevin Backhouse of GHSL.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Helps: GHSL-2021-045
Helps: #2319
2021-02-04 14:13:03 +00:00
Sebastian Dröge
8385664f47 Merge branch 'master' into 'master'
gdatetime: Add math library support

Closes #2314

See merge request GNOME/glib!1916
2021-02-04 08:03:22 +00:00
Xavier Claessens
580b415ebd atomic: Fix type check of g_atomic_pointer_compare_and_exchange() 2021-02-03 09:37:04 -05:00
Xavier Claessens
7459bf9a19 Revert "atomic: Fix type error with clang++"
This reverts commit d95885d91e.
2021-02-03 09:37:04 -05:00
Philip Withnall
ab46205db1 Merge branch 'carlosgc/uri-host-nullable' into 'master'
guri: Mark g_uri_get_host as nullable

See merge request GNOME/glib!1921
2021-02-03 09:59:29 +00:00
Carlos Garcia Campos
5221b6a261 guri: Mark g_uri_get_host as nullable
It's currently annotated as not nullable, but it can be NULL.
2021-02-03 09:47:30 +00:00
Prasanth R
62fc437773 gdatetime: Add math library support
W.r.to c3805d74b uClibc fails in linking
Fixes #2314
2021-02-03 14:09:10 +05:30
Sebastian Dröge
e38982df4b Merge branch 'atomic-typeof' into 'master'
Define glib_typeof with C++11 decltype()

Closes #2226

See merge request GNOME/glib!1715
2021-02-02 10:51:50 +00:00
Sebastian Dröge
02fbe86e07 Mark g_key_file_get_comment() key parameter as nullable
It will return the comment above the group (or at the top of the file)
then according to the documentation.
2021-02-02 10:14:57 +02:00
Philip Withnall
6cca256526 Merge branch 'wip/avoid-searching-path' into 'master'
spawn: Don't set a search path if we don't want to search PATH

See merge request GNOME/glib!1902
2021-02-01 11:58:51 +00:00
Simon McVittie
f378352051 tests: Mark tests with AddressSanitizer-detected leaks
Various tests have leaks where it isn't clear whether the data is
intentionally not freed, or leaked due to a bug. If we mark these
tests as TODO, we can skip them under AddressSanitizer and get the
rest to pass, giving us a baseline from which to avoid regressions.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-02-01 11:19:59 +00:00
Simon McVittie
41ed1c6d5d gutils: Tell AddressSanitizer not to track previous XDG directories
We reset these in some unit tests, and must deliberately leak them to
avoid having to break API.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-02-01 10:44:35 +00:00