Commit Graph

117 Commits

Author SHA1 Message Date
Enrico Weigelt, metux IT consult 43dd9e5f43 dix: clean up MakeWindowOptional() calls and add alloc fault checks
a) no need to checking for win->optional == NULL before calling
   MakeWindowOptional(), because it checks itself
   (except some cases where it's presence has it's own semantics,
   or prevent unnecessary allocations)
b) lots of call sites didn't check for allocation failure.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 17:21:48 +02:00
Enrico Weigelt, metux IT consult 3c028a8cc0 miext: move over extinit_priv.h from include
Since most of the extension init logic (and on/off switches for them)
is driven from miext, this seems the appropriate place for the header.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 17:21:46 +02:00
Enrico Weigelt, metux IT consult dda64fcadf xext: replace xallocarray() by calloc()
Only key difference that calloc(), in contrast to rellocarray(),
is zero-initializing. The overhead is hard to measure on today's
machines, and it's safer programming practise to always allocate
zero-initialized, so one can't forget to do it explicitly.

Cocci rule:

    @@
    expression COUNT;
    expression LEN;
    @@
    - xallocarray(COUNT,LEN)
    + calloc(COUNT,LEN)

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 17:21:43 +02:00
Enrico Weigelt, metux IT consult 535a110c60 Xext: clean up including panoramix headers
* use their actual path instead of relying this to be in compiler's
  include path list.
* no need to do it only conditionally, no #ifdef needed

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 17:21:43 +02:00
Enrico Weigelt, metux IT consult adc27c5220 dix: move ColormapRec declaration out of public header
Not used by any external module/driver, so no need to keep it in
public header.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 17:21:43 +02:00
Enrico Weigelt, metux IT consult 4ac10378e1 dix: unexport and rename CreateWindow()
a) an internal function that's not used by any drivers
b) conflicting with function/define of same name on win32

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 17:21:43 +02:00
Enrico Weigelt, metux IT consult c96901a85a Xext: use calloc() instead of malloc()
Using calloc() instead of malloc() as preventive measure, so there
never can be any hidden bugs or leaks due uninitialized memory.

The extra cost of using this compiler intrinsic should be practically
impossible to measure - in many cases a good compiler can even deduce
if certain areas really don't need to be zero'd (because they're written
to right after allocation) and create more efficient machine code.

The code pathes in question are pretty cold anyways, so it's probably
not worth even thinking about potential extra runtime costs.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 16:48:11 +02:00
Enrico Weigelt, metux IT consult 7ce19233bc Xext: saver: use dixDestroyPixmap() instead of direct driver call
Direct calls to ScreenRec->DestroyPixmap() blocks cleaning up the wrapping
jungle, so use the proper dix function instead.

See: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1754

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1711>
2025-02-12 17:48:30 +01:00
Enrico Weigelt, metux IT consult 356e18dcc6 os: move out extension disable flags to corresponing extensions
The OS abstraction isn't really the right place for those flags,
they are're probably better off in their corresponding extensions.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1519>
2025-02-07 12:00:53 +01:00
Enrico Weigelt, metux IT consult 37dd2897d4 Xext: saver: consolidate (non-)xinerama versions
We can make it a bit simpler by doing the request header
checking only once.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1591>
2025-02-06 23:56:51 +00:00
Enrico Weigelt, metux IT consult 8236ef3b56 Xext: saver: use explicit switch/case for dispatching
It's more robust / easier understandable programming style to use explicit
switch statements, case'ing on the constants defined in the protocol header,
instead of implicitly via a some opaque call table. It's also done this
way in the other extensions, so making the code a bit more consistent.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1591>
2025-02-06 23:56:51 +00:00
Enrico Weigelt, metux IT consult 40469a9d51 Xext: saver: skip unneeded zero init and zero-swapping
When using struct initializers, all fields not set explicitly are zero.
Also no need to swap fields that are known to be zero.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1591>
2025-02-06 23:56:51 +00:00
Enrico Weigelt, metux IT consult fdb8c8ea41 Xext: saver: fix missing swap in QueryVersion reply
The `majorVersion` and `minorVersion` fields are CARD16, thus need to be swapped.
OTOH, the lengths field is zero anyways, so no need to swap it.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1591>
2025-02-06 23:56:51 +00:00
Enrico Weigelt, metux IT consult 07131dccc5 Xext: saver: drop now obsolete swap procs
Several SProc's have become no-ops, just calling the actual Proc's,
so we can get rid of them entirely.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1639>
2025-02-06 22:28:52 +00:00
Enrico Weigelt, metux IT consult b52f5f9693 Xext: saver: drop swapping request length fields
The request struct's length fields aren't used anymore - we have the
client->req_len field instead, which also is bigreq-compatible.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1639>
2025-02-06 22:28:50 +00:00
Enrico Weigelt, metux IT consult bacc4b1477 Xext: saver: fix length checking with bigreq
The authorative source of the request frame size is client->req_len,
especially with big requests larger than 2^18 bytes.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1639>
2025-02-06 22:28:48 +00:00
Enrico Weigelt, metux IT consult fb696a7d7b rename old symbol PANORAMIX to XINERAMA
PANORAMIX was the original working title of the extension, before it became
official standard. Just nobody cared about fixing the symbols to the official
naming.

For backwards compatibility with drivers, the old PANORAMIX symbol will
still be set.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1258>
2025-02-06 15:51:27 +00:00
Enrico Weigelt, metux IT consult 1642adec3b dix: unexport Ones()
It's not used by any module/driver, so no need to keep it exported.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1695>
2024-10-26 16:35:57 +00:00
Enrico Weigelt, metux IT consult a917f6a8a8 drop obsolete HAVE_DIX_CONFIG_H
The symbol controls whether to include dix-config.h, and it's always set,
thus we don't need it (and dozens of ifdef's) anymore.

This commit only removes them from our own source files, where we can
guarantee that dix-config.h is present - leaving the (potentially exported)
headers untouched.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2024-10-10 13:38:31 +00:00
Enrico Weigelt, metux IT consult 4aadbeb8aa dix: unexport cursor refcounting functions
These aren't used externally (drivers/modules), thus no need to export them.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1345>
2024-09-02 16:43:29 +00:00
Enrico Weigelt, metux IT consult a3ec1a829d dix: unexport IsMapInstalled()
Not used by any driver/module, so no need to keep it exported.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1581>
2024-09-01 22:06:50 +00:00
Enrico Weigelt, metux IT consult 811977228b os: unexport screen saver timer functions
These functions aren't supposed to be used by drivers, so move them
out of the public API.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1583>
2024-09-01 20:23:10 +00:00
Enrico Weigelt, metux IT consult fba3eefcc9 Xext: saver: little bit formatting cleanup
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1586>
2024-07-06 17:29:11 +00:00
Enrico Weigelt, metux IT consult df38987656 Xext: saver: drop New() macro
We can directly use calloc() as all other places do.

If we wanna have an convenient macro for struct allocation, that would be the
job of a separate patch queue and should be done consequently, treewide.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1586>
2024-07-06 17:29:10 +00:00
Enrico Weigelt, metux IT consult 06b599edb6 dix: unexport fields from opaque.h not used by modules/drivers
Lots of fields from opaque.h aren't used by any drivers/modules and thus
don't need to be exported at all.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1351>
2024-06-23 21:19:27 +00:00
Enrico Weigelt, metux IT consult 305f2d59d8 xace: typesafe hook function for XACE_SCREENSAVER_ACCESS
he generic XaceHook() call isn't typesafe (und unnecessarily slow).
Better add an explicit function, just like we already have for others.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1556>
2024-06-23 21:07:48 +00:00
Enrico Weigelt, metux IT consult 33350ef8ff include: move private definitions out of extinit.h
Public server module API shouldn't be clobbered with private definitions,
thus move them out to extinit_priv.h.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1289>
2024-04-30 00:47:38 +00:00
Enrico Weigelt, metux IT consult 85d4bd0dba rename remaining RT_* defines to X11_RESTYPE_*
Since we already had to rename some of them, in order to fix name clashes
on win32, it's now time to rename all the remaining ones.

The old ones are still present as define's to the new ones, just for
backwards compatibility.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1355>
2024-04-15 19:00:47 -07:00
Enrico Weigelt, metux IT consult 232cad9ec3 prevent name clash on Windows w/ RT_* defines
Windows' native headers using some our RT_* define's names for other things.
Since the naming isn't very nice anyways, introducing some new ones
(X11_RESTYPE_NONE, X11_RESTYPE_FONT, X11_RESTYPE_CURSOR) and define the old
ones as an alias to them, in case some out-of-tree code still uses them.

With thins change, we don't need to be so extremely careful about include
ordering and have explicit #undef's in order to prevent name clashes on
Win32 targets.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1355>
2024-04-15 18:59:23 -07:00
Enrico Weigelt, metux IT consult d444cd4237 dix: unexport some lookup functions
These aren't used by any drivers, so no need to export them.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1380>
2024-04-15 18:11:57 -07:00
Peter Hutterer 842ca3ccef Xext: free the screen saver resource when replacing it
This fixes a use-after-free bug:

When a client first calls ScreenSaverSetAttributes(), a struct
ScreenSaverAttrRec is allocated and added to the client's
resources.

When the same client calls ScreenSaverSetAttributes() again, a new
struct ScreenSaverAttrRec is allocated, replacing the old struct. The
old struct was freed but not removed from the clients resources.

Later, when the client is destroyed the resource system invokes
ScreenSaverFreeAttr and attempts to clean up the already freed struct.

Fix this by letting the resource system free the old attrs instead.

CVE-2022-46343, ZDI-CAN 19404

This vulnerability was discovered by:
Jan-Niklas Sohn working with Trend Micro Zero Day Initiative

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Olivier Fourdan <ofourdan@redhat.com>
2022-12-14 11:02:40 +10:00
Povilas Kanapickas 6c4c530107 Xext: Fix out of bounds access in SProcScreenSaverSuspend()
ZDI-CAN-14951, CVE-2021-4010

This vulnerability was discovered and the fix was suggested by:
Jan-Niklas Sohn working with Trend Micro Zero Day Initiative

Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2021-12-14 15:00:02 +02:00
Alan Coopersmith 23e83724df Fix spelling/wording issues
Most (but not all) of these were found by using
  codespell --builtin clear,rare,usage,informal,code,names
but not everything reported by that was fixed.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2020-07-05 13:07:33 -07:00
Keith Packard 52048ce29f Xext/saver: Swap ScreenSaverSuspend 'suspend' field. Handle old XCB clients.
This field was defined as a Bool in the protocol headers and BOOL in
xcb. Bool is not a valid type for protocol fields. It is defined as
'int' by Xdefs.h, which we expect to be 32-bits on all machines.

The protocol headers and xcb have patches posted to switch to CARD32,
which is at least well defined.

This change adds the necessary byte swapping to handle other-endian
clients with this 32-bit field, and then changes the request
processing to compare all 32-bits against zero so that it works with
both new and old clients.

On MSB machines, Xlib will continue to work properly, but old XCB will
not interoperate with the X server (either before or after this patch).

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Mihai Moldovan <ionic@ionic.de>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2018-03-14 10:14:04 -07:00
Daniel Martin d5379b350f Use ARRAY_SIZE all over the tree
Roundhouse kick replacing the various (sizeof(foo)/sizeof(foo[0])) with
the ARRAY_SIZE macro from dix.h when possible. A semantic patch for
coccinelle has been used first. Additionally, a few macros have been
inlined as they had only one or two users.

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2017-10-30 13:45:20 -04:00
Nathan Kidd cad5a1050b Unvalidated lengths
v2: Add overflow check and remove unnecessary check (Julien Cristau)

This addresses:
CVE-2017-12184 in XINERAMA
CVE-2017-12185 in MIT-SCREEN-SAVER
CVE-2017-12186 in X-Resource
CVE-2017-12187 in RENDER

Reviewed-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
Reviewed-by: Julien Cristau <jcristau@debian.org>
Signed-off-by: Nathan Kidd <nkidd@opentext.com>
Signed-off-by: Julien Cristau <jcristau@debian.org>
2017-10-10 23:33:34 +02:00
Adam Jackson 3360418767 dpms: Consolidate a bunch of stuff into Xext/dpms.c
Most of this is a legacy of the old "extmod" design where you could load
_some_ extensions dynamically but only if the server had been built with
support for them in the first place.

Note that since we now only initialize the DPMS extension if at least
one screen supports it, we no longer need DPMSCapableFlag: if it would
be false, we would never read its value.

Signed-off-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
2017-03-27 15:59:47 -04:00
Adam Jackson dc7ceda90f dispatch: Mark swapped dispatch as _X_COLD
This touches everything that ends up in the Xorg binary; the big missing
part is GLX since that's all generated code. Cuts about 14k from the
binary on amd64.

Signed-off-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
2017-03-01 10:16:20 -05:00
Adam Jackson a5dd7b890f dix: Squash some new gcc6 warnings
-Wlogical-op now tells us:

    devices.c:1685:23: warning: logical ‘and’ of equal expressions

Reviewed-by: Julien Cristau <jcristau@debian.org>
Signed-off-by: Adam Jackson <ajax@redhat.com>
2016-04-29 11:19:58 -04:00
Alan Coopersmith 1c56ac63c0 Convert top level extensions to new *allocarray functions
v2: remove now useless parentheses

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
2015-04-21 16:57:08 -07:00
Adam Jackson 2db71b232c saver: Don't open-code IsMapInstalled
Reviewed-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Adam Jackson <ajax@redhat.com>
2014-07-29 09:52:22 -04:00
Keith Packard 2d2d49dab5 Clean up a few function prototypes to not place formals in /**/
This just removes the comment markers from around the formals in
several function prototypes near where pointer -> void * changes were
made. There are plenty more of these to fix.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2014-01-12 10:24:12 -08:00
Keith Packard 60014a4a98 Replace 'pointer' type with 'void *'
This lets us stop using the 'pointer' typedef in Xdefs.h as 'pointer'
is used throughout the X server for other things, and having duplicate
names generates compiler warnings.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
2014-01-12 10:24:11 -08:00
Peter Hutterer efc1035ca9 dix: provide accessor methods for the last device event time
And now that we have the accessors, localize it. No functional changes, just
preparing for a future change.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Keith Packard <keithp@keithp.com>
2013-10-18 16:44:32 +10:00
Peter Hutterer 9a5ad65330 Abstract cursor refcounting
Too many callers relied on the refcnt being handled correctly. Use a simple
wrapper to handle that case.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-05-15 19:17:57 +10:00
Yaakov Selkowitz ea1d76d1b6 Fix formatting of address operators
The formatter confused address operators preceded by casts with
bitwise-and expressions, placing spaces on either side of both.
That syntax isn't used by ordinary address operators, however,
so fix them for consistency.

Signed-off-by: Yaakov Selkowitz <yselkowitz@users.sourceforge.net>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2012-12-05 18:09:48 -06:00
Peter Hutterer 2dc6d92284 When resetting device idle time, reset XIAll(Master)Devices too (#56649)
When the screen saver is forcibly deactivated, the idle time counter is
reset for all devices but not for the fake XIAllDevices and
XIAllMasterDevices. XScreenSaverQueryInfo uses XIAlldevices to fill the
"idle" field, thus returning the wrong value.

Regression introduced in
commit 6aef209ebc
Author: Peter Hutterer <peter.hutterer@who-t.net>
Date:   Mon Mar 12 13:51:02 2012 +1000

    Change lastDeviceIdleTime to be per-device

X.Org Bug 56649 <http://bugs.freedesktop.org/show_bug.cgi?id=56649>

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Tested-by: Giacomo Perale <ghepeu@virgilio.it>
Reviewed-by: Keith Packard <keithp@keithp.com>
2012-11-29 14:48:54 +10:00
Daniel Stone a1d41e311c Move extension initialisation prototypes into extinit.h
Create extinit.h (and xf86Extensions.h, for Xorg-specific extensions) to
hold all our extension initialisation prototypes, rather than
duplicating them everywhere.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Keith Packard <keithp@keithp.com>
2012-07-09 23:06:41 -07:00
Tomas Carnecky 5079db78ae Replace INITARGS with void
INITARGS was a hardcoded define to void.  Since knowing the function
signature for your extensions is kinda useful, just replace it with a
hardcoded void, but leave the define there for API compatibility.

Signed-off-by: Tomas Carnecky <tom@dbservice.com>
Reviewed-by: Daniel Stone <daniel@fooishbar.org>
Reviewed-by: Cyril Brulebois <kibi@debian.org>
Reviewed-by: Jamey Sharp <jamey@minilop.net>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Keith Packard <keithp@keithp.com>
2012-07-09 23:06:41 -07:00
Alan Coopersmith 9805cedf7b Use C99 designated initializers in extension Events
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Keith Packard <keithp@keithp.com>
Tested-by: Daniel Stone <daniel@fooishbar.org>
2012-07-09 22:52:30 -07:00