Commit graph

23 commits

Author SHA1 Message Date
Chloé Vulquin
172c8add7d xcursor: catch theme inheritance loops
As of currently, when an xcursor theme depends on itself or another theme
that will eventually depend on it, `xcursor_load_theme` will recurse
infinitely while processing the inherits.

This change introduces a stack-allocated linked list of visited nodes
by name, and skips any already visited nodes in the inherit list.

Side effects:
* Since the linked list is stack-allocated, there is a potential for an
  overflow if there is a very long list of dependencies. If this turns out
  to be a legitimate concern, the linked list is trivial to convert to
  being heap-allocated.
* There is an existing linked list (technically doubly linked list)
  implementation in the wayland codebase. As of currently, the xcursor
  codebase does not refer to it. Consequently, this change writes a
  minimal single linked list implementation to utilize directly.

This changeset is based on the merge request in wayland/wayland!376.
The xcursor code is mostly shared between the two.
This changeset diverges the files slightly due to stylistic differences
between the repositories, but the logic is identical.

Signed-off-by: Chloé Vulquin <toast@bunkerlabs.net>
2024-04-09 11:12:03 +03:00
Simon Ser
842093bb84 Define _POSIX_C_SOURCE globally
Stop trying to maintain a per-file _POSIX_C_SOURCE. Instead,
require POSIX.1-2008 globally. A lot of core source files depend
on that already.

Some care must be taken on a few select files where we need a bit
more than POSIX. Some files need XSI extensions (_XOPEN_SOURCE) and
some files need BSD extensions (_DEFAULT_SOURCE). In both cases,
these feature test macros imply _POSIX_C_SOURCE. Make sure to not
define both these macros and _POSIX_C_SOURCE explicitly to avoid
POSIX requirement conflicts (e.g. _POSIX_C_SOURCE says POSIX.1-2001
but _XOPEN_SOURCE says POSIX.1-2008).

Additionally, there is one special case in render/vulkan/vulkan.c.
That file needs major()/minor(), and these are system-specific.
On FreeBSD, _POSIX_C_SOURCE hides system-specific symbols so we need
to make sure it's not defined for this file. On Linux, we can
explicitly include <sys/sysmacros.h> and ensure that apart from
symbols defined there the file only uses POSIX toys.
2024-02-15 15:41:12 +01:00
Paul Cercueil
220df2aa0f
Add more POSIX compliance macros to fix uClibc support
- Add POSIX 1993.09 compliance macro in source files that use
  "struct timespec";
- Add POSIX 2001.12 compliance macro in source files that use
  "struct sigaction" and the SA_SIGINFO macro, or the fchmod()
  function;
- Add POSIX 2008.09 compliance macro in source files that use the
  getline() function.

These compliance macros are enough for wlroots to compile with the
git-master version of uClibc-ng.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
2024-02-12 17:41:45 +01:00
Kirill Primak
e16b0068a7 xcursor: fix NULL deref on malloc() fail 2023-11-19 15:33:39 +03:00
Alexander Orzechowski
1b0694b794 treewide: Migrate from sizeof(struct) to sizeof(*pointer) where practical 2023-10-03 01:51:07 -04:00
Edgars Cīrulis
17ad034480 xcursor: Resolve warning in xcursor_build_theme_dir
Signed-off-by: Edgars Cīrulis <edgarsscirulis@gmail.com>
2023-04-25 10:16:59 +00:00
Simon Ser
25d9055281 xcursor: sync with libwayland
xcursor.c was copied over from libwayland-cursor. A lot of
cosmetic imporvements have been merged upstream. Copy-paste the
new version.
2023-04-18 14:54:25 +00:00
Simon Ser
311381c6b5 xcursor: use internal_config
Removes a project argument, improves escaping.
2022-12-06 22:39:45 +00:00
Antonin Décimo
95d3529edf xcursor: check that XDG base directory path is absolute
The spec reads:

> All paths set in these environment variables must be absolute. If an
> implementation encounters a relative path in any of these variables it should
> consider the path invalid and ignore it.

and

> If $XDG_DATA_HOME is either not set or empty, a default equal to
> $HOME/.local/share should be used.

Testing that the path is absolute also entails that is is non-empty.
2022-05-02 15:15:24 +02:00
Moon Sungjoon
2dd121235e xcursor: support XDG Base Directory Specification
This patch adds ~/.local/share/icons to the search path, so user-specific
themes can be loaded through the API provided by libwayland-cursor.

Use this PR as reference:
https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/112
2022-03-08 15:41:42 +00:00
Vlad Zahorodnii
ab3b9f9a77 xcursor: garbage collect XcursorLibraryLoadImages
XcursorLibraryLoadImages is unused, let's drop it.

Same as [1].

[1]: https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/206

Co-authored-by: Simon Ser <contact@emersion.fr>
2022-01-31 14:10:08 +00:00
Tobias Stoeckmann
d0c1f0c0b6 xcursor: fix CVE-2013-2003
The libXcursor fix for CVE-2013-2003 has never been imported into
wlroots, leaving it vulnerable to it.

Changing the argument type to an unsigned type is an effective merge of
Ilja Van Sprundel's commit in libXcursor.

Proof of Concept (compile with address sanitizer):

$ mkdir -p ~/.local/share/icons/poc/cursors
$ base64 -d <<< WGN1chAAAAAAAAAA/////w== > \
    ~/.local/share/icons/poc/cursors/poc
$ echo "seat seat0 xcursor_theme poc 10" > ~/poc-config
$ sway -c ~/poc-config
2021-05-02 17:04:59 +02:00
Yuya Nishihara
3c5cc02b18 xcursor: use memcpy() to append string of known size
Since len <= strlen(elt) is known, we don't need a str*() function. Let's
simply do memcpy() to suppress linter false positive.

Fixes #2777.
2021-04-13 16:55:46 +02:00
Yuya Nishihara
a71d565138 Revert "xcursor: use strncat instead of strncpy"
This reverts commit 7dffe9339b, which introduced
another linter error with -O3:

  error: ‘strncat’ specified bound 7 equals source length [-Werror=stringop-overflow=]

This makes sense because strncat(dest, "cursors", strlen("cursors")) is moot
in security point of view.

The next commit will replace strncpy() with memcpy(), so let's restore the
original implementation.
2021-04-13 16:55:46 +02:00
Lukas Märdian
7dffe9339b xcursor: use strncat instead of strncpy
strncat appends '\0' automatically and avoids the stringop-truncation
warning/error
2021-03-08 12:03:48 +01:00
Lukas Märdian
d8a422575b Fix false positive -Wstringop-truncation
Fix false positive stringop-truncation warning/error with GCC 10 on s390x by indicating GCC to explicitly ignore this case, as it is clearly a false positive (NUL is set in the following line).

This allow the compilation to succeed with -Werror on.

Fixes: https://github.com/swaywm/wlroots/issues/2018
2021-03-08 12:03:48 +01:00
Valentin
65abd4e92a Fix undefined behavior
Without the casts the bytes accesses get converted to int. but int is
not guaranteed to be 4 bytes large. Even when it is 4 bytes large
`bytes[3] << 24` does not fit because int is signed.
2020-09-01 11:58:56 +02:00
Kirill Chibisov
6c8f66ff59 xcursor: add xorg-x11 and cursors path to XCURSORPATH
This should match default XCURSORPATH, which is used by libwayland-cursor
and other xcursor loading libraries more closely.
2020-06-26 11:20:52 +02:00
Cosimo Cecchi
14f45c056f
xcursor: Support XDG user data dir location
Nowadays ~/.icons is not used anymore as the preferred location for custom
user icon themes; XDG_DATA_HOME/icons (aka ~/.local/share/icons) is what
toolkits like GTK prefer. Prepend that location to the default xcursor path, so
that cursor themes installed there can be used by apps and toolkits that use
libXcursor.

Port of https://cgit.freedesktop.org/xorg/lib/libXcursor/commit/src?id=2263c196cb0dcb8547b378df7b35f83b8b99c01e
2018-11-27 23:21:07 +01:00
Philipp Ludwig
e7fba556a8
xcursor: fix crash when encountering cursor themes with circular dependencies
Port of https://cgit.freedesktop.org/xorg/lib/libXcursor/commit/src?id=f64a8cc1a65dcad4294e2988b402a34175019663
2018-11-27 23:19:26 +01:00
Tobias Stoeckmann
de0a032d8e
xcursor: Fix heap overflows when parsing malicious files
It is possible to trigger heap overflows due to an integer overflow
while parsing images.

The integer overflow occurs because the chosen limit 0x10000 for
dimensions is too large for 32 bit systems, because each pixel takes
4 bytes. Properly chosen values allow an overflow which in turn will
lead to less allocated memory than needed for subsequent reads.

See also:
https://cgit.freedesktop.org/xorg/lib/libXcursor/commit/?id=4794b5dd34688158fb51a2943032569d3780c4b8
5d201df72f
2018-11-06 14:40:41 +01:00
emersion
c2e1474010
Reformat all #include directives 2018-02-12 21:29:23 +01:00
Drew DeVault
7486263f7e Add xcursor sublibrary 2017-08-07 21:13:04 -04:00