aboutsummaryrefslogtreecommitdiffstats
path: root/cursor
Commit message (Collapse)AuthorAgeFilesLines
* cursor: Free theme when size check fails to avoid memory leakYaoBing Xiao2025-08-031-3/+3
| | | | Signed-off-by: YaoBing Xiao <xiaoyaobing@uniontech.com>
* cursor: Properly check realloc for errorsTobias Stoeckmann2025-06-081-6/+7
| | | | | | | Do not override realloc's input pointer before checking for errors, otherwise it's not possible to keep old value, as intended. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
* cursor: Ignore invalid cursor filesTobias Stoeckmann2025-06-081-0/+2
| | | | | | | The header offset must not be smaller than file header length. Ignore such invalid files. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
* cursor: Gracefully handle huge cursor filesTobias Stoeckmann2025-06-081-2/+12
| | | | | | | | | | If cursor files require more than INT_MAX bytes, it is possible to trigger out of boundary writes. Since these sizes are most likely not desired anyway, gracefully handle these situations like out of memory errors. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
* cursor: Gracefully handle out of memory conditionTobias Stoeckmann2025-06-081-1/+5
| | | | | | | If the full path could not be constructed, avoid calling opendir(NULL) which, depending on library, might trigger undefined behavior. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
* cursor: Fix undefined behavior with huge namesTobias Stoeckmann2025-06-081-1/+1
| | | | | | | | | | | If an index.theme contains a theme name which gets close to INT_MAX, then creation of full path can lead to a signed integer overflow, which is undefined behavior. Fix this by turning one of the values to size_t. Easy solution for a probably never occurring issue. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
* Fix typosTobias Stoeckmann2025-05-201-3/+3
| | | | | | Typos found with codespell and during code audit. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
* cursor: add check to ensure wl_shm_create_pool succeededYaoBing Xiao2024-10-181-0/+5
| | | | Signed-off-by: YaoBing Xiao <xiaoyaobing@uniontech.com>
* src: Finish assert() clean-upDerek Foreman2024-08-091-1/+0
| | | | | | | | | | | | | From cleanup commit 0cecde304: assert()s can be compiled away by #defining NDEBUG. Some build systems do this. Using wl_abort gives a human readable error message and it isn't compiled away. That commit missed one final assert, presumably due to missing it with grep because of a coding style issue. Fix that up, and remove inclusion of <assert.h> as appropriate. Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
* xcursor: catch theme inheritance loopsChloé Vulquin2024-04-241-24/+66
| | | | | | | | | | | | | | | | | | | | | | | 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 fixes #317. Signed-off-by: Chloé Vulquin <toast@bunkerlabs.net>
* cursor: memfd_create: try MFD_NOEXEC_SEAL6t8k2024-04-211-1/+20
| | | | | | | | | | | | | | Effective from Linux 6.3 onward, this creates the memfd without execute permissions and prevents that setting from ever being changed. A run-time fallback is made to not using MFD_NOEXEC_SEAL when a libwayland-cursor compiled on Linux >= 6.3 is run on Linux < 6.3. This is a defense-in-depth security measure and silences a respective kernel warning; see: https://lwn.net/Articles/918106/ This implementation is adopted from dnkl's `foot` terminal emulator. Signed-off-by: 6t8k <6t8k@noreply.codeberg.org>
* cursor: add aliases for cursor name specConsolatis2024-01-191-0/+15
| | | | | | | | | | | The cursor name spec [1] describes how cursors should be named, and is widely used. Add aliases so that users can pass these names to libwayland-cursor without having to add fallbacks for X11 cursor names. [1]: https://www.freedesktop.org/wiki/Specifications/cursor-spec/ Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: check return value of snprintf()Simon Ser2023-08-021-1/+6
| | | | | | | | | | | | | | | | | | | | Fixes a new warning in GCC 7: FAILED: cursor/libwayland-cursor.so.0.22.90.p/xcursor.c.o cc -Icursor/libwayland-cursor.so.0.22.90.p -Icursor -I../cursor -I. -I.. -Isrc -I../src -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Werror -std=c99 -O3 -D_POSIX_C_SOURCE=200809L -Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -fvisibility=hidden -fPIC '-DICONDIR="/usr/share/X11/icons"' -MD -MQ cursor/libwayland-cursor.so.0.22.90.p/xcursor.c.o -MF cursor/libwayland-cursor.so.0.22.90.p/xcursor.c.o.d -o cursor/libwayland-cursor.so.0.22.90.p/xcursor.c.o -c ../cursor/xcursor.c ../cursor/xcursor.c: In function 'xcursor_load_theme': ../cursor/xcursor.c:596:39: error: '%s' directive output between 7 and 7 bytes may cause result to exceed 'INT_MAX' [-Werror=format-truncation=] 596 | snprintf(full, full_size, "%s/%s/%s", dir, subdir, file); | ^~ ...... 764 | full = xcursor_build_fullname(dir, "cursors", ""); | ~~~~~~~~~ ../cursor/xcursor.c:596:41: error: '/' directive output between 1 and 1 bytes may cause result to exceed 'INT_MAX' [-Werror=format-truncation=] 596 | snprintf(full, full_size, "%s/%s/%s", dir, subdir, file); | ^ cc1: all warnings being treated as errors Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: make param names match with documentationSimon Ser2022-09-131-24/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There was a mismatch here. Use a good-looking function param name because that's what will show up in docs. Use an abbreviation inside the function. Fixes the following warnings: cursor/wayland-cursor.c:504: warning: argument 'cursor' of command @param is not found in the argument list of wl_cursor_frame(struct wl_cursor *_cursor, uint32_t time) cursor/wayland-cursor.c:504: warning: The following parameter of wl_cursor_frame(struct wl_cursor *_cursor, uint32_t time) is not documented: parameter '_cursor' cursor/wayland-cursor.c:452: warning: argument 'cursor' of command @param is not found in the argument list of wl_cursor_frame_and_duration(struct wl_cursor *_cursor, uint32_t time, uint32_t *duration) cursor/wayland-cursor.c:452: warning: The following parameter of wl_cursor_frame_and_duration(struct wl_cursor *_cursor, uint32_t time, uint32_t *duration) is not documented: parameter '_cursor' cursor/wayland-cursor.c:147: warning: argument 'image' of command @param is not found in the argument list of wl_cursor_image_get_buffer(struct wl_cursor_image *_img) cursor/wayland-cursor.c:147: warning: The following parameter of wl_cursor_image_get_buffer(struct wl_cursor_image *_img) is not documented: parameter '_img' cursor/wayland-cursor.c:504: warning: argument 'cursor' of command @param is not found in the argument list of wl_cursor_frame(struct wl_cursor *_cursor, uint32_t time) cursor/wayland-cursor.c:504: warning: The following parameter of wl_cursor_frame(struct wl_cursor *_cursor, uint32_t time) is not documented: parameter '_cursor' cursor/wayland-cursor.c:452: warning: argument 'cursor' of command @param is not found in the argument list of wl_cursor_frame_and_duration(struct wl_cursor *_cursor, uint32_t time, uint32_t *duration) cursor/wayland-cursor.c:452: warning: The following parameter of wl_cursor_frame_and_duration(struct wl_cursor *_cursor, uint32_t time, uint32_t *duration) is not documented: parameter '_cursor' cursor/wayland-cursor.c:147: warning: argument 'image' of command @param is not found in the argument list of wl_cursor_image_get_buffer(struct wl_cursor_image *_img) cursor/wayland-cursor.c:147: warning: The following parameter of wl_cursor_image_get_buffer(struct wl_cursor_image *_img) is not documented: parameter '_img' Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor/os-compatibility: handle EINTR gracefullyOlivier Fourdan2022-06-091-2/+20
| | | | | | | | | | | | | | If os_resize_anonymous_file() called from os_create_anonymous_file() fails with EINTR (Interrupted system call), then the buffer allocation fails. To avoid that, retry posix_fallocate() on EINTR. However, in the presence of an alarm, the interrupt may trigger repeatedly and prevent a large posix_fallocate() to ever complete successfully, so we need to first block SIGALRM to prevent this. Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
* Check that XDG base directories paths are absoluteAntonin Décimo2022-06-092-2/+2
| | | | | | | | | | | | | | | | | | | The [spec][1] 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. [1]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html Signed-off-by: Antonin Décimo <antonin.decimo@gmail.com>
* cursor/os-compatibility: fix trailing spaceSimon Ser2022-06-041-1/+1
| | | | Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor/os-compatibility: remove strcpy/strcat usageSimon Ser2022-06-041-3/+5
| | | | | | | These functions don't perform bounds checking, so they are easy to misuse and complicate audits. Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: move xcursor_theme_inherits declarations at the topSimon Ser2022-05-271-2/+4
| | | | | | | | Per code style, declarations need to be at the start of the block. And make l const while at it. Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: drop xcursor_add_path_eltSimon Ser2022-05-271-38/+13
| | | | | | | Just use snprintf instead. It doesn't really matter if we have some duplicate slashes in filenames. Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: drop unused XCursor comment declarationsSimon Ser2022-05-271-33/+0
| | | | Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: fix indentation of xcursor_load_theme declarationSimon Ser2022-05-271-2/+2
| | | | Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: simplify xcursor_library_pathSimon Ser2022-05-271-16/+16
| | | | | | | | | | - Use early returns - De-duplicate XDG_DATA_HOME code-paths - Don't crash on allocation failure - Use size_t when appropriate - Fix indentation Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: remove unnecessary ifs in xcursor_load_themeSimon Ser2022-05-271-10/+5
| | | | | | | load_all_cursors_from_dir and xcursor_theme_inherits already have the NULL checks we want. Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: drop xcursor_images_set_nameSimon Ser2022-05-271-19/+1
| | | | | | | | We don't ever need to set the name multiple times for a single struct xcursor_images, so we can just set the field directly. Also replace the hand-rolled logic with strdup. Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: use getline instead of fgetsSimon Ser2022-05-271-2/+5
| | | | | | | This avoids storing 8KiB on the stack, and removes the line length limit. Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: remove unnecessary parentheses in load_all_cursors_from_dirSimon Ser2022-05-271-1/+2
| | | | Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: remove xcursor_file_load_images wrapperSimon Ser2022-05-271-10/+1
| | | | | | It's just calling xcursor_xc_file_load_images. Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: rename local variables to snake caseSimon Ser2022-05-231-75/+75
| | | | Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: drop xcursor_file abstractionSimon Ser2022-05-231-50/+10
| | | | | | Just use FILE * directly instead. Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: refactor xcursor_theme_inheritsSimon Ser2022-05-231-29/+33
| | | | | | | Use early returns and breaks to avoid dealing with very long indentation lines. Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: convert macros to functionsSimon Ser2022-05-231-3/+16
| | | | | | | | Improves readability since there's no need for so many parentheses anymore, adds type safety. The compiler will inline the function automatically as necessary. Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: rename functions to snake caseSimon Ser2022-05-233-99/+99
| | | | Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: fix whitespace in function args definitionsSimon Ser2022-05-231-15/+13
| | | | Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: remove struct typedefs, rename to snake caseSimon Ser2022-05-233-78/+76
| | | | Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: fix spacing around conditions and loopsSimon Ser2022-05-231-53/+33
| | | | Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: fix indentationSimon Ser2022-05-231-409/+409
| | | | | | Use tabs. Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: remove unnecessary if before freeSimon Ser2022-05-231-7/+3
| | | | | | free(NULL) is valid and is a no-op. Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: fix variable declaration styleSimon Ser2022-05-231-46/+46
| | | | | | Use a single space between type and variable name. Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: fix struct declaration styleSimon Ser2022-05-232-32/+32
| | | | | | Use tabs for indentation, don't use tabs to align field names. Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: fix define styleSimon Ser2022-05-231-18/+18
| | | | | | Don't use tabs, don't align. Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: drop whitespace before parens in function callsSimon Ser2022-05-232-127/+127
| | | | | | This is in line with the rest of the Wayland code style. Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: drop XCURSOR_LIB_* definesSimon Ser2022-05-231-12/+0
| | | | | | These are unused. Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: drop XcursorTrue and XcursorFalseSimon Ser2022-05-231-20/+13
| | | | | | Just use <stdbool.h> instead. Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: remove private Xcursor int typedefsSimon Ser2022-05-232-48/+43
| | | | | | Just use the types directly instead. Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: use MAP_FAILED instead of hardcoded constantSimon Ser2022-05-061-1/+1
| | | | Signed-off-by: Simon Ser <contact@emersion.fr>
* cursor: Remove unused XcursorLibraryLoadImages() functionVlad Zahorodnii2022-02-052-80/+0
| | | | | | | XcursorLibraryLoadImages() function is unused and not exported according to objdump, so its removal should be an ABI compatible change. Signed-off-by: Vlad Zahorodnii <vlad.zahorodnii@kde.org>
* build: don't rely on implicit GNU extensionsSimon Ser2022-01-101-0/+1
| | | | | | | | | Currently libwayland assumes GNU extensions will be available, but doesn't define the C standard to use. Instead, let's unconditionally enable POSIX extensions, and enable GNU extensions on a case-by-case basis as needed. Signed-off-by: Simon Ser <contact@emersion.fr>
* meson: override dependencies to ease use as subprojectSimon Ser2021-12-081-0/+9
| | | | | | | | | | | | | Make it easier to use Wayland as a Meson subproject by overriding dependencies we define. This allows to easily build Wayland as a subproject like so: subproject('wayland', required: false, default_options: ['documentation=false']) After this statement, the wayland-* dependencies will use the subproject instead of the system if available. Signed-off-by: Simon Ser <contact@emersion.fr>
* build: Include the Wayland minor version in libraries' ABI versionsSimon McVittie2021-10-281-1/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The ABI of a shared library on Linux is given by a major version, which is part of the SONAME and is incremented (rarely) on incompatible changes, and a minor version, which is part of the basename of the regular file to which the SONAME provides a symlink. Until now, the ABI minor version was hard-coded, which means we can't tell which of a pair of Wayland libraries is newer (and therefore likely to have more symbols and/or fewer bugs). libwayland-egl already had ABI major version 1, so we can use the "marketing" version number as the ABI major.minor version number directly, so Wayland 1.19.90 would produce libwayland-egl.so.1 -> libwayland-egl.so.1.19.90. libwayland-cursor and libwayland-server have ABI major version 0, and OS distributions don't like it when there's a SONAME bump for no good reason, so use their existing ABI major version together with the "marketing" minor version: libwayland-cursor.so.0 -> libwayland-cursor.so.0.19.90. If the Wayland major version number is incremented to 2, we'll have to rethink this, so add some error() to break the build if/when that happens. Assuming that Wayland 2.0 would involve breaking changes, the best way would probably to bump all the SONAMEs to libwayland-foo.so.2. Resolves: https://gitlab.freedesktop.org/wayland/wayland/-/issues/175 Signed-off-by: Simon McVittie <smcv@collabora.com>