Commit graph

459 commits

Author SHA1 Message Date
Alan Coopersmith
321392ded1 Remove unused ETEST & ESZTEST macros from XlibInt.c
Left behind when 15e5eaf628 removed support for building without XCB.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Jasper St. Pierre <jstpierre@mecheye.net>
2014-01-05 10:27:54 -08:00
Alan Coopersmith
1ffc0c5503 _XkbReadGeomOverlay: check for NULL first, then use pointer
Flagged by cppcheck 1.62:
[lib/libX11/src/xkb/XKBGeom.c:479] -> [lib/libX11/src/xkb/XKBGeom.c:480]:
 (warning) Possible null pointer dereference: row - otherwise it is
 redundant to check it against null.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-12-26 09:26:13 -08:00
Alan Coopersmith
ddf5f130cc XkbSelectEventDetails: remove unnecessary assignments
clear & selectAll are set to 0 already a few lines earlier,
affectWhich is set to XkbMapNotifyMask a few lines later.
None are used between the other assignments and the removed ones.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-12-26 09:22:49 -08:00
Alan Coopersmith
7e16330073 unifdef -UISC
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-12-02 21:51:27 -08:00
Alan Coopersmith
0e45f64766 Drop X_LOCALE fallback for OS'es without setlocale()
C89 or bust!   This was documented as being needed for "only Lynx,
Linux-libc5, OS/2" and has never been enabled in modular builds,
since none of those platforms have had anyone step up to add support
since the X11R7 conversion to autotools.

Mostly performed with unifdef -UX_LOCALE, followed by removal of files
left without any purpose, and manual cleanup of remaining references.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2013-11-22 22:02:17 -08:00
Alan Coopersmith
6cb02b1663 Xcms file parsing should not require the impossible to succeed
The field2 helper function, to split lines from Xcms.txt files into
two tab delimited fields, contained a check:

    if ((*pBuf != '\n') || (*pBuf != '\0')) {
        return(XcmsFailure);

which would cause it to return failure unless *pBuf had a value that
was simultaneously equal to both \n & \0, and no one wants to live in
a world where that could ever be true.

This has gone unnoticed since 1991, since this only caused lines
in Xcms.txt that started with whitespace to be rejected, but now
gcc -Wlogicalop has brought it to our attention, and
https://bugs.freedesktop.org/show_bug.cgi?id=70803 was filed.

Now that we see it, and cannot unsee it, we change it to use the
same logic as the check at other points in this function, to return
failure only if we hit \n or \0 before we find the first non-whitespace
character, so that lines starting with whitespace will have the space
skipped over to get to the color name to be defined.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Dan Nicholson <dbn.lists@gmail.com>
2013-10-25 09:27:37 -07:00
Gaetan Nadon
18a5278b00 makekeys: don't need to use target-specific CFLAGS
It's the only thing built in that directory, so we can use AM_CFLAGS
and AM_CPPFLAGS as usual.

Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Signed-off-by: Gaetan Nadon <memsize@videotron.ca>
2013-09-30 13:24:04 -04:00
Alan Coopersmith
c2b8e30790 Stop checking for HAVE_DIX_CONFIG_H on the client side
Leftover from when these XKB files were shared with the server sources
and could be compiled in either the client or server, with the different
autoconf config files in each.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-08-20 12:51:10 -07:00
Alan Coopersmith
84276609b2 Rearrange some variable declarations & initializations in XKB
Little things noticed during XKB restyling that seemed to make the
code easier to read.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-08-20 12:51:10 -07:00
Alan Coopersmith
b90b7e859c Reindent XKB code to X.Org standard style
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-08-20 12:51:10 -07:00
Alan Coopersmith
c0a0f78eb4 Fix overflow checks in _XkbReadKeySyms when key_sym_map is already created
We were checking to make sure that the largest keysym value was within
the range of the allocated buffer, but checking against different limits
in the not-yet-allocated vs. the already-allocated branches.

The check should be the same in both, and reflect the size used for the
allocation, which is based on the maximum key code value, so we move it
to be a common check, before we branch, instead of duplicating in each
branch.

map->key_sym_map is an array of XkbSymMapRec structs, [0..max_key_code]
map->syms is the array for which num_syms is recorded, hence is not the
right value to check for ensuring our key_sym_map accesses are in range.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reported-by: Barry Kauler <bkauler@gmail.com>
Tested-by: Barry Kauler <bkauler@gmail.com>
2013-08-20 12:51:10 -07:00
Alan Coopersmith
bea6cbd027 Remove long unused src/udcInf.c
I can find no record of what this file was for.  Neither the X11R6.8.2
monolith Imakefile nor any modular release Makefile.am have ever built
it and nothing else references it.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-08-20 12:51:09 -07:00
Alan Coopersmith
bf3501e039 Remove unnecessary casts of pointers to (char *) in calls to Xfree()
Left one cast behind that is necessary to change from const char *
to char * in src/xlibi18n/lcCharSet.c.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-08-20 12:51:09 -07:00
Alan Coopersmith
6ead9dd92a Don't cast sizeof() results to unsigned when passing to Xmalloc/Xcalloc
sizeof() returns size_t, malloc() & calloc() expect sizes in size_t,
don't strip down to unsigned int and re-expand unnecessarily.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-08-20 12:51:09 -07:00
Alan Coopersmith
25a7a329de Remove even more casts of return values from Xmalloc/Xrealloc
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-08-20 12:51:09 -07:00
Alan Coopersmith
f8fa16092a xlibi18n: fix argsize argument to _XlcParsePath
The array is defined as having NUM_LOCALEDIR entries, so use that
instead of hardcoded 256 value (the other two calls already did this).

Reported by parfait:
   Buffer overflow (CWE 120): In pointer dereference of argv[argc] with index argc
      Pointer size is 64 elements (of 8 bytes each), index is 255
        at line 82 of src/xlibi18n/lcFile.c in function 'parse_line'.
        called at line 178 in function '_XlcParsePath' with argv = argv.
        called at line 722 in function '_XlcLocaleLibDirName' with argv = args, argsize = 256.
        at line 82 of src/xlibi18n/lcFile.c in function 'parse_line'.
        called at line 178 in function '_XlcParsePath' with argv = argv.
        called at line 638 in function '_XlcLocaleDirName' with argv = args, argsize = 256.

[ This bug was found by the Parfait 1.2.0 bug checking tool.
  http://labs.oracle.com/pls/apex/f?p=labs:49:::::P49_PROJECT_ID:13 ]

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-08-20 12:51:09 -07:00
Alan Coopersmith
cbd86eccf1 xlibi18n: Fix a bunch of const cast warnings
Add const qualifiers to casts where needed, remove other casts that
are no longer needed.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-08-20 12:51:09 -07:00
Alan Coopersmith
eb3676113f Fix const handling in XSetLocaleModifiers
Instead of reusing the input parameter to store the output, make a
result variable instead, so that there's less const confusion.

Fixes gcc warnings:
lcWrap.c: In function 'XSetLocaleModifiers':
lcWrap.c:87:18: warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual]
lcWrap.c:91:25: warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual]
lcWrap.c:93:12: warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual]

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-08-20 12:51:08 -07:00
Alan Coopersmith
8ebbffa985 Constify lc_name argument to _XlcLocaleDirName() & _XlcLocaleLibDirName()
Makes code considerably less crufty and clears gcc warnings:
XlcDL.c: In function '_XlcDynamicLoad':
XlcDL.c:384:44: warning: cast discards '__attribute__((const))' qualifier
 from pointer target type [-Wcast-qual]
XlcDL.c:386:51: warning: cast discards '__attribute__((const))' qualifier
 from pointer target type [-Wcast-qual]

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-08-20 12:51:08 -07:00
Alan Coopersmith
07e4e86410 init_om: remove unneeded extra copy of string to local buffer
Strings from the supported_charset_list[] were being copied one by
one to a stack buffer, and then strdup called on that buffer.

Instead, just strdup the original string, without the local copy,
and use a more traditional for loop, so it's easier to figure out
what the code is doing (cleaning up a gcc const-cast warning in
the process).

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Matthieu Herrb <matthieu.herrb@laas.fr>
2013-08-20 12:51:06 -07:00
Alan Coopersmith
1cec14dad9 Delete unused XKB_INSURE_SIZE macro from XKBlibint.h
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Matthieu Herrb <matthieu.herrb@laas.fr>
2013-08-20 12:51:05 -07:00
Alan Coopersmith
5f32182c7c miRegionOp(): ensure region size is not updated if realloc fails
This function performs operations on a region, and when finished,
checks to see if it should compact the rectangle list.  If the
number of rectangles for which memory is allocated in the list is
more than twice the number used, it tries to shrink.   realloc()
should not fail in this case, but if it does, might as well keep
the correct value for the number of allocated rectangles, so we
don't try to grow it unnecessarily later if adding to the region.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-08-20 12:51:04 -07:00
Alan Coopersmith
bd2a0b5a18 miRegionCopy(): handle realloc failure better
Zero out the region size when freeing the region so callers don't think
there's anything there.   (Pointer is already set to NULL from the realloc
result itself.)  Return 0 to the callers, and have them cascade that back
to their callers to indicate failure, instead of their usual return value
of 1 on success.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-08-20 12:51:04 -07:00
Alan Coopersmith
b3fea74ec5 lcDB.c: ensure buffer size is updated correctly if realloc fails
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-08-20 12:51:04 -07:00
Alan Coopersmith
43bb822c71 Avoid memory leak/corruption if realloc fails in XlcDL.c:resolve_object()
Previously, if realloc failed to increase the size, we'd still
record that we had allocated the larger size, but the pointer
to it would be NULL, causing future calls to be broken, and the
previous allocation to be lost/leaked.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Matthieu Herrb <matthieu.herrb@laas.fr>
2013-08-20 12:50:54 -07:00
Alan Coopersmith
4fadae243f xlibi18n: convert sprintf calls to snprintf
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Matthieu Herrb <matthieu.herrb@laas.fr>
2013-08-20 12:50:40 -07:00
Alan Coopersmith
36a7edf0e5 lcfile: skip over any null entries in args list
Previous code seemed to assume that printf("%s", NULL) would result
in a 0-length string, not "(null)" or similar, but since there's no
point looking for files in "(null)/filepath...", instead we just
skip over NULL entries in search paths when generating file names.

In the *DirName() functions, this effectively just moves the "bail on
NULL in arg[i]" check up from the later code that assigned it to targetdir
and then bailed if that was NULL.

Not sure how there ever could be a NULL in arg[i], given the current
implementation of XlcParsePath, but it's easy enough to check once and
reject up front instead of on every reference.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-08-20 12:50:40 -07:00
Alan Coopersmith
ee0824f243 Fix file leak on malloc error in XlcDL.c:resolve_object()
File Leak: Leaked File fp
   at line 219 of lib/libX11/src/xlibi18n/XlcDL.c in function 'resolve_object'.
      fp initialized at line 198 with fopen

[ This bug was found by the Parfait 1.2.0 bug checking tool.
  http://labs.oracle.com/pls/apex/f?p=labs:49:::::P49_PROJECT_ID:13 ]

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Matthieu Herrb <matthieu.herrb@laas.fr>
2013-08-20 12:50:19 -07:00
Alan Coopersmith
d19cfaca15 Fix undefined XCMSDIR error when building lint library
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-07-29 20:11:10 -07:00
Alan Coopersmith
7db74514e4 Refactor common code from XAddHost & XRemoveHost into single function
On the Xlib side, the only real difference is the mode flag we send
to the server with the address, so just make that an argument to the
function with the common code for packing the address into the request.

(Aside from labels, gcc 4.7.2 generates identical code before & after
 this change due to inlining, verified via diff of gcc -S output.)

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-07-23 22:33:52 -07:00
Alan Coopersmith
3292195a64 XSetModifierMapping: Use Data instead of GetReqExtra
Handle arbitrary length data in the same fashion as other calls,
avoiding need to ensure it fits all in the request buffer.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-07-23 22:14:05 -07:00
Kees Cook
feb131b18a libX11: check "req" when calling GetReqExtra
This fixes the two callers of GetReqExtra to check that "req" is non-NULL
to avoid crashing now that GetReqExtra does internal bounds-checking on
the resulting buffer sizes.

Additionally updates comment describing return values to use names
instead of only literal values.

Signed-off-by: Kees Cook <kees@outflux.net>
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-07-22 23:51:48 -07:00
Kees Cook
54540d7cba libX11: check size of GetReqExtra after XFlush
Two users of GetReqExtra pass arbitrarily sized allocations from the
caller (ModMap and Host). Adjust _XGetRequest() (called by the GetReqExtra
macro) to double-check the requested length and invalidate "req" when
this happens. Users of GetReqExtra passing lengths greater than the Xlib
buffer size (normally 16K) must check "req" and fail gracefully instead
of crashing.

Any callers of GetReqExtra that do not check "req" for NULL
will experience this change, in the pathological case, as a NULL
dereference instead of a buffer overflow. This is an improvement, but
the documentation for GetReqExtra has been updated to reflect the need
to check the value of "req" after the call.

Bug that manifested the problem:
https://bugs.launchpad.net/ubuntu/+source/x11-xserver-utils/+bug/792628

Signed-off-by: Kees Cook <kees@outflux.net>
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-07-22 23:51:38 -07:00
Thomas Klausner
24d3ee0d08 Tighten out-of-range comparisons.
[For all of these, LONG_MAX was the correct value to prevent overflows
 for the recent CVEs.   Lowering to INT_MAX catches buggy replies from
 the server that 32-bit clients would reject but 64-bit would accept,
 so we catch bugs sooner, and really, no sane & working server should
 ever report more than 2gb of extension names, font path entries,
 key modifier maps, etc.  -alan- ]

Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-07-21 13:06:43 -07:00
Thomas Klausner
6d926088d8 Fix out-of-range comparison in _XF86BigfontQueryFont
clang complained (correctly):
warning: comparison of constant 768614336404564650 with expression
of type 'CARD32' (aka 'unsigned int') is always true
[-Wtautological-constant-out-of-range-compare]

[While LONG_MAX is correct, since it's used in size_t math, the
 numbers have to be limited to 32-bit range to be usable by 32-bit
 clients, and values beyond that range are far more likely to be
 bugs in the data from the server than valid numbers of characters
 in a font.   -alan- ]

Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-07-21 11:05:55 -07:00
Thomas Klausner
383e2b0d02 Check for symbol existence with #ifdef, not #if
Reviewed-by: Jamey Sharp <jamey@minilop.net>

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-07-08 23:13:14 -07:00
Alan Coopersmith
a336db9a0a Require ANSI C89 pre-processor, drop pre-C89 token pasting support
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-06-24 23:02:05 -07:00
Thomas Klausner
ed3d830243 Deal with the limited range of VAX floating point numbers when compiling for VAX.
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-06-06 23:11:45 -07:00
Thomas Klausner
4a89b7ea90 cmsMath.c: Add missing stdio header for printf(3) in DEBUG build.
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-06-02 16:22:40 -07:00
Julien Cristau
a3bdd2b090 xkb: fix off-by-one in _XkbReadGetNamesReply and _XkbReadVirtualModMap
The size of the arrays is max_key_code + 1.  This makes these functions
consistent with the other checks added for CVE-2013-1997.

Also check the XkbGetNames reply when names->keys was just allocated.

Signed-off-by: Julien Cristau <jcristau@debian.org>
Tested-by: Colin Walters <walters@verbum.org>
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-05-23 20:39:46 +02:00
Niveditha Rau
7e30056e78 Make sure internal headers include required headers
Fixes builds with Solaris Studio 12.3 when lint is enabled, since it no
longer ignores *.h files, but complains when they reference undefined
typedefs or macros.

Signed-off-by: Niveditha Rau <Niveditha.Rau@Oracle.COM>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-05-17 15:27:31 -07:00
Alan Coopersmith
2820100bf8 Free fs->properties in _XF86BigfontQueryFont overflow error path
Fixes small memory leak introduced in commit 5669a22081

Reported-by: Julien Cristau <jcristau@debian.org>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-05-16 23:05:36 -07:00
Matthieu Herrb
3131740513 XListFontsWithInfo: Re-decrement flist[0] before calling free() on it.
Freeing a pointer that wasn't returned by malloc() is undefined
behavior and produces an error with OpenBSD's implementation.

Signed-off-by: Matthieu Herrb <matthieu.herrb@laas.fr>
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-05-09 18:59:54 -07:00
Alan Coopersmith
e1b457beb8 _XkbReadGetMapReply: reject maxKeyCodes smaller than the minKeyCode
Various other bounds checks in the code assume this is true, so
enforce it when we first get the data from the X server.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-05-09 18:59:54 -07:00
Alan Coopersmith
12ad4c6432 Use calloc in XOpenDisplay to initialize structs containing pointers
Prevents trying to free uninitialized pointers if we have to bail out
partway through setup, such as if we receive a corrupted or incomplete
connection setup block from the server.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-05-09 18:59:54 -07:00
Alan Coopersmith
d38527e25f Remove more unnecessary casts from Xmalloc/calloc calls
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2013-05-09 18:59:54 -07:00
Alan Coopersmith
b2c86b582c Convert more _XEatData callers to _XEatDataWords
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Matthieu Herrb <matthieu.herrb@laas.fr>
2013-05-09 18:59:53 -07:00
Alan Coopersmith
192bbb9e2f Make XGetWindowProperty() always initialize returned values
Avoids memory corruption and other errors when callers access them
without checking to see if XGetWindowProperty() returned an error value.

Callers are still required to check for errors, this just reduces the
damage when they don't.

Reported-by: Ilja Van Sprundel <ivansprundel@ioactive.com>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Matthieu Herrb <matthieu.herrb@laas.fr>
2013-05-09 18:59:53 -07:00
Alan Coopersmith
db1b1c871d Avoid overflows in XListExtensions() [CVE-2013-1997 15/15]
Ensure that when breaking the returned list into individual strings,
we don't walk past the end of allocated memory to write the '\0' bytes

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Matthieu Herrb <matthieu.herrb@laas.fr>
2013-05-09 18:59:53 -07:00
Alan Coopersmith
8d59365949 Avoid overflows in XGetFontPath() [CVE-2013-1997 14/15]
Ensure that when breaking the returned list into individual strings,
we don't walk past the end of allocated memory to write the '\0' bytes

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Matthieu Herrb <matthieu.herrb@laas.fr>
2013-05-09 18:59:53 -07:00