Commit graph

24 commits

Author SHA1 Message Date
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
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
f807ac9c78
cppcheck style-fixes
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
2021-05-05 20:25:26 -04: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
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
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
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
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
Alan Coopersmith
e086eb1bf4 Strip trailing whitespace
Performed with: find * -type f | xargs perl -i -p -e 's{\s+$}{\n}'
git diff -w & git diff -b show no diffs from this change

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2011-09-16 21:26:17 -07:00
Chris Wilson
f49e7e1608 Free the partial header after failing to open the cursor.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-04-01 12:16:56 +01:00
Matthieu Herrb
04641d3cc3 nuke RCS Ids 2008-03-09 00:34:36 +01:00
Alan Coopersmith
9df9640643 Fix many sparse warnings: Using plain integer as NULL pointer 2006-10-10 14:57:16 -07:00
Chris Wilson
e0a501e91c fix leak in header destruction
Fix a couple of if (!foo) free(foo); tests.
2006-08-12 19:55:44 +03:00
Daniel Stone
c6f65af419 Bug #5268: Fix small memory leak. (Matthias Clasen). Change some return 0s
to NULL. Bump to 1.1.7.
2006-06-03 10:23:57 +00:00
Daniel Stone
caa910e492 Import Xcursor 1.1.4 from freedesktop.org xlibs tree. 2005-06-29 18:46:53 +00:00
Markus Kuhn
50911b052c Encoding of numerous files changed to UTF-8 2004-12-04 00:42:47 +00:00
Egbert Eich
cbcf471d91 Merging XORG-CURRENT into trunk 2004-04-23 18:43:40 +00:00
Egbert Eich
fb1739bd22 Importing vendor version xf86-4_4_99_1 on Sun Mar 14 00:26:39 PST 2004 2004-03-14 08:32:05 +00:00
Egbert Eich
bfcfbe061f Importing vendor version xf86-4_4_0 on Wed Mar 3 04:09:24 PST 2004 2004-03-03 12:11:23 +00:00
Egbert Eich
c450b74503 readding XFree86's cvs IDs 2004-02-26 13:35:32 +00:00
Egbert Eich
79b8e8b996 Importing vendor version xf86-4_3_99_903 on Wed Feb 26 01:21:00 PST 2004 2004-02-26 09:22:42 +00:00
Kaleb Keithley
3b84b14bf0 Initial revision 2003-11-14 16:48:48 +00:00