Commit graph

86 commits

Author SHA1 Message Date
Albert Astals Cid
f3305d7922 Fix memory leak in _XcursorXcFileLoadImage
fileHeader needs to be freed in the two early returns
2026-01-04 03:00:40 +01:00
Haelwenn (lanodan) Monnier
f9a2078c0f Add SPDX-License-Identifier: HPND-sell-variant
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libxcursor/-/merge_requests/25>
2025-06-16 12:32:52 +02:00
Thomas E. Dickey
8ae6cf61b1
amend per merge_requests/22#note_2642042
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2024-11-04 04:06:21 -05:00
Thomas E. Dickey
68fe24020c
amend per merge_requests/22#note_2642034
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2024-11-04 04:00:20 -05:00
Thomas E. Dickey
d8b955d6b2
fix overlooked compiler-warning
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2024-11-03 18:58:23 -05:00
Thomas E. Dickey
cb2d1b97c3
add debug-trace for the configuration information
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2024-11-03 18:58:16 -05:00
Thomas E. Dickey
304ac296f3
ensure ncomment and nimage values are positive
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2024-11-03 18:58:09 -05:00
Thomas E. Dickey
83071fff3f
document/tidy the new set/get functions
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2024-11-03 18:57:56 -05:00
Thomas E. Dickey
f155414617
add traces for library.c and xlib.c, also another internal function for dpy
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2024-11-03 18:57:43 -05:00
Thomas E. Dickey
fbfe95e05f
add debug-logging for file.c, to help with analysis
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2024-11-03 18:57:36 -05:00
Thomas E. Dickey
8a1de72216
add/use _XcursorLibraryLoadImages to pass resized-parameter when loading
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2024-11-03 18:57:29 -05:00
Thomas E. Dickey
b00d7da27b
use resized-parameter where available when loading images
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2024-11-03 18:57:23 -05:00
Thomas E. Dickey
5cb505f21e
provide internal variants of existing functions to pass "resized" parameter
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2024-11-03 18:57:16 -05:00
Thomas E. Dickey
e7272c8046
restore behavior of image-loading, provide resizing via internal function
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2024-11-03 18:57:10 -05:00
Thomas E. Dickey
6816ed58e9
add getter/setter for "resized" property
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2024-11-03 18:57:03 -05:00
Thomas E. Dickey
e5e63e2ba8
add new property "resized" and environment "XCURSOR_RESIZED"
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2024-11-03 18:56:57 -05:00
Thomas E. Dickey
a5739d863b
trim redundant code from the resize-calls
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2024-11-03 18:56:49 -05:00
Thomas E. Dickey
7e03738efd
fix compiler warnings
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2024-11-03 18:56:38 -05:00
Thomas E. Dickey
b09856069c
build-fix
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2024-11-03 18:56:30 -05:00
Jin Liu
dfc8561247
Remove unnecessary MIN calls 2024-11-03 18:56:12 -05:00
Jin Liu
a21cdaf167
Change all *LoadImage(..., size) APIs to always return a cursor with the requested size.
Callers of these APIs (especially on Wayland) currently uses different
strategies to scale the returned cursor to the size set by the user,
resulting in inconsistent cursor sizes and looks across different apps
and toolkits. Having the cursor scaled in libXcursor will skip app's
own scaling algorithm and guarantee a consistent look.

`*LoadAllImages()` are not changed. They still only return the sizes present
in the theme.

This change needs to be synchronized to libraries (libxcb-cursor, wayland),
toolkits (GTK), window managers / Wayland compositors (i3, wlroots) who have
a (modified) copy of libXcursor source code, in order to have a fully consistent
cursor size across all apps.

Signed-off-by: Jin Liu <m.liu.jin@gmail.com>
2024-11-03 18:56:04 -05:00
Tobias Stoeckmann
833735e323 Ignore invalid cursor files
If a cursor file contains a header offset which is too small, ignore
the file instead of jumping to an incorrect offset.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2024-09-12 22:23:50 +02:00
Robin Linden
3783190da9 Remove superfluous and unguarded config.h include
config.h is correctly included behind a HAVE_CONFIG_H guard earlier in
the file, so this isn't needed.

Signed-off-by: Robin Linden <dev@robinlinden.eu>
2024-01-18 18:38:13 +01:00
Alan Coopersmith
5e0f8347ce XcursorXcFileLoad: plug memory leak in error paths
Found by gcc analyzer:
file.c: In function ‘XcursorXcFileLoad’:
file.c:782:8: warning: leak of ‘fileHeader’ [CWE-401] [-Wanalyzer-malloc-leak]
  782 |     if (!images)
      |        ^

Fixes: 3b84b14 ("Initial revision")
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2023-10-08 10:48:25 -07:00
Alan Coopersmith
9c1b50ed98 Add comment about keeping libxcb-cursor copy of code in sync
_XcursorThemeInherits, XcursorWhite, & XcursorSep are copied in
libxcb-cursor/cursor/load_cursor.c and should be kept in sync
with changes to the libXcursor originals of those.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2023-07-08 11:07:03 -07:00
Alan Coopersmith
a353f02a7a If O_CLOEXEC is defined, add "e" to fopen modes
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2023-03-25 12:14:36 -07:00
Thomas E. Dickey
801925839d
more cppcheck-style fixes
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2021-05-06 20:12:37 -04:00
Thomas E. Dickey
f807ac9c78
cppcheck style-fixes
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2021-05-05 20:25:26 -04:00
Tobias Stoeckmann
6edf1caf6f fix XcursorTheme loop regression
Handle themes with multiple inherit entries. Although the previous
commit keeped track of inherited themes, it only handled multiple theme
entries on the highest level.

This fix unconditionally checks if the next upper level contains a line.
If it does, it processes contained themes (i.e. the current theme had an
inherited entry in its index file).

If the upper level has no more themes, it goes down a level and
processes the next theme there. If no next theme exists, it moves down
another level and so on until it reaches level 0, i.e. the initially
supplied theme.

The lowest level (d = 0) is treated specially because we must not modify
the supplied theme, which could happen when calling _XcursorNextPath.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2021-05-04 18:59:46 +02:00
Tobias Stoeckmann
b47ca9858e Handle more theme loop situations
This is a follow up for commit f64a8cc1a6
resulting from https://bugs.freedesktop.org/show_bug.cgi?id=3603

The current loop detection only works for direct self references but not
for transitive ones. Limiting the inheritance depth fixes this issue as
suggested by Keith Packard.

I avoided the introduction of a recursion function. Instead I modified
XcursorScanTheme to work iterative.

The current recursion code adds the "Inherits=..." line to heap and has
an iteration variable to go through all themes listed in that line per
recursion. This is covered with the newly introduced XcursorInherit
struct with its fields "line" and "theme". Since "theme" points into
"line", only "line" has to be freed eventually.

If a fixed inheritage limit of 32 is reached, the code stops processing
and returns NULL. It also returns NULL if it detects the initial theme
in one of the inheritages to break the loop early on.

Last but not least I removed the printf statement. The only situation in
which libXcursor writes to stdout is when it is explicitly requested.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2021-05-02 16:27:38 +02:00
Thomas E. Dickey
fb377b9a71
amend that...
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2021-03-11 20:25:40 -05:00
Thomas E. Dickey
362fdcfc3e
add check in case the image size is 0x0
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2021-03-11 20:25:34 -05:00
Thomas E. Dickey
09f69a8829
fix stricter gcc warnings using casts
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2021-03-11 20:25:29 -05:00
Thomas E. Dickey
152f8e45db
fix stricter gcc warnings using casts
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2021-03-11 20:25:22 -05:00
Thomas E. Dickey
628cde0575
fix stricter gcc warnings by changing the type for the loop variable to
match the type of the loop limit

Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2021-03-11 20:25:15 -05:00
Thomas E. Dickey
ce907e36e0
quiet warnings for unused parameters
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2021-03-11 20:25:09 -05:00
Thomas E. Dickey
7623dae73c
fix a missing initializer
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2021-03-11 20:25:03 -05:00
Thomas E. Dickey
cea72e1427
quiet normal gcc warnings using casts (no object change)
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2021-03-11 20:24:54 -05:00
Valentin
204b6f1308 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-08-30 15:37:19 +02:00
Cosimo Cecchi
2263c196cb 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.
2018-11-09 20:06:41 -08:00
Philipp Ludwig
f64a8cc1a6 Fix crash when encountering cursor themes with circular dependencies.
https://bugs.freedesktop.org/show_bug.cgi?id=3603

Signed-off-by: Philipp Ludwig <git-devel@philippludwig.net>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2018-03-23 23:22:22 -07:00
Tobias Stoeckmann
4794b5dd34 Fix heap overflows when parsing malicious files. (CVE-2017-16612)
It is possible to trigger heap overflows due to an integer overflow
while parsing images and a signedness issue while parsing comments.

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.

The signedness bug is triggered by reading the length of a comment
as unsigned int, but casting it to int when calling the function
XcursorCommentCreate. Turning length into a negative value allows the
check against XCURSOR_COMMENT_MAX_LEN to pass, and the following
addition of sizeof (XcursorComment) + 1 makes it possible to allocate
less memory than needed for subsequent reads.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Matthieu Herrb <matthieu@herrb.eu>
2017-11-25 11:52:34 +01:00
shubham shrivastav
897213f36b Insufficient memory for terminating null of string in _XcursorThemeInherits
Fix does one byte of memory allocation for null termination of string.
https://bugs.freedesktop.org/show_bug.cgi?id=90857

Reviewed-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2015-06-05 13:36:22 -07:00
Alan Coopersmith
edf52212a0 Fix some clang integer sign/size mismatch warnings
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2014-10-18 10:52:49 -07:00
Alan Coopersmith
bbf3c582c9 Use strdup() instead of malloc(strlen())+strcpy()
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2014-10-18 10:24:13 -07:00
Alan Coopersmith
8f677eaea0 signedness bug & integer overflow in _XcursorFileHeaderCreate() [CVE-2013-2003]
When parsing cursor files, a user defined (e.g. through environment
variables) cursor file is opened and parsed.

The header is read in _XcursorReadFileHeader(), which reads an unsigned
int for the number of toc structures in the header, but it was being
passed to _XcursorFileHeaderCreate() as a signed int to allocate those
structures.  If the number was negative, it would pass the bounds check
and could overflow the calculation for how much memory to allocate to
store the data being read, leading to overflowing the buffer with the
data read from the user controlled file.

Reported-by: Ilja Van Sprundel <ivansprundel@ioactive.com>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-04-26 17:22:43 -07:00
Alan Coopersmith
1b98fd6a2e Replace deprecated Automake INCLUDES variable with AM_CPPFLAGS
Excerpt https://lists.gnu.org/archive/html/automake/2012-12/msg00038.html

  - Support for the long-deprecated INCLUDES variable will be removed
    altogether in Automake 1.14.  The AM_CPPFLAGS variable should be
    used instead.

This variable was deprecated in Automake releases prior to 1.10, which is
the current minimum level required to build X.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-01-15 18:51:39 -08:00
Alan Coopersmith
8229cf75b3 XcursorImageLoadCursor: return failure if _XcursorGetDisplayInfo fails
Error: Null pointer dereference (CWE 476)
   Read from null pointer 'info'
        at line 615 of src/cursor.c in function 'XcursorImageLoadCursor'.
          Function '_XcursorGetDisplayInfo' may return constant 'NULL' at line 134, called at line 597.
          Null pointer introduced at line 134 of src/display.c in function '_XcursorGetDisplayInfo'.

[ This bug was found by the Parfait 0.3.7 bug checking tool.
  For more information see http://labs.oracle.com/projects/parfait/ ]

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Jeremy Huddleston <jeremyhu@apple.com>
2011-11-30 18:59:43 -08:00
Alan Coopersmith
2b8d373bdd XcursorFileSaveImages: plug memory leak on invalid input
Error: Memory leak (CWE 401)
   Memory leak of pointer 'comments' allocated with XcursorCommentsCreate(0)
        at line 982 of src/file.c in function 'XcursorFileSaveImages'.
          'comments' allocated at line 978 with XcursorCommentsCreate(0).
          comments leaks when comments != 0 at line 981.

[ This bug was found by the Parfait 0.3.7 bug checking tool.
  For more information see http://labs.oracle.com/projects/parfait/ ]

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Jeremy Huddleston <jeremyhu@apple.com>
2011-11-30 18:59:33 -08:00
Jon TURNEY
862b9ce4aa Fix install of generated Xcursor.h when builddir != srcdir
Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by:  Gaetan Nadon <memsize@videotron.ca>
Tested-by: Gaetan Nadon <memsize@videotron.ca>
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2011-09-25 13:15:30 +01:00