XQuartz: Silence some static analyzer warnings by annotating referencing counts

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
(cherry picked from commit 9da6c0918f40359f28fe8889d5b7cae7efcc8377)
XQuartz: Fix darwinfb.h header guard

./darwinfb.h:28:9: warning: '_DARWIN_FB_H' is used as a header guard here, followed by #define of a different macro
      [-Wheader-guard,Lexical or Preprocessor Issue]
        ^~~~~~~~~~~~
./darwinfb.h:29:9: note: '_DARWIN_DB_H' is defined here; did you mean '_DARWIN_FB_H'? [Lexical or Preprocessor Issue]
        ^~~~~~~~~~~~
        _DARWIN_FB_H

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
(cherry picked from commit 2e3ebec9520719a8e5c3c92390e83bcb5216f978)
XQuartz: Fix get_proc_address signature

indirect.c:675:28: warning: incompatible pointer types passing 'glx_gpa_proc (*)(const char *)' to parameter of type
      'glx_gpa_proc' (aka 'glx_func_ptr (*)(const char *)') [-Wincompatible-pointer-types,Semantic Issue]
    __glXsetGetProcAddress(&get_proc_address);
                           ^~~~~~~~~~~~~~~~~
../../../glx/glxserver.h:122:42: note: passing argument to parameter 'get_proc_address' here [Semantic Issue]
void __glXsetGetProcAddress(glx_gpa_proc get_proc_address);
                                         ^

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
(cherry picked from commit ea80279e292e59a9fe9651489f03e9f2f39810d9)
XQuartz: Mark applicationWillTerminate: noreturn

X11Controller.m:938:1: warning: method 'applicationWillTerminate:' could be declared with attribute 'noreturn'
      [-Wmissing-noreturn,Semantic Issue]
{
^

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
(cherry picked from commit f79af1941776fd6f1ec26c50603fcc35ca7d514b)
XQuartz: Simplify hook_run to quiet static analyzer

x-hook.c:96:9: warning: Called function pointer is an uninitalized pointer value
        (*fun[i])(arg, data[i]);
        ^~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
(cherry picked from commit 959e8f23af7850fcaf40d6c67f5228241a36a9ab)
XQuartz: Validate screen in AppleDRIQueryDirectRenderingCapable requests

Return an error to the caller rather than crashing the server on
invalid screens.

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
(cherry picked from commit b3572c0d1ab7888ac26d6b2b8be6d1d19ed9af3f)
XQuartz: Validate length in appledri before swapping

Avoids potential memory corruption from bad requests

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
(cherry picked from commit a03f096a85537d9e881cedaa6cb71aca43a97086)
XQuartz: Silence a clang static analysis warning about a possible memory leak on exit

stub.c:356:9: warning: Potential leak of memory pointed to by 'newargv'
        asl_log(aslc, NULL, ASL_LEVEL_ERR,
        ^~~~~~~
stub.c:356:9: warning: Potential leak of memory pointed to by 'newenvp'
        asl_log(aslc, NULL, ASL_LEVEL_ERR,
        ^~~~~~~
2 warnings generated.

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
(cherry picked from commit b2f6b3497c33a4897afae80a2cf69c596b9f81e8)
XQuartz: Silence a clang static analysis warning about a memory leak

It seems the alanyzer can't comprehend dixSetPrivate().

quartz.c:119:12: warning: Potential leak of memory pointed to by 'displayInfo'
    return quartzProcs->AddScreen(index, pScreen);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
(cherry picked from commit 64327226ddfba8f0653615cd678d2d4336fb993d)
XQuartz: Check for allocated memory before using it in AppleWMSetWindowMenu

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
(cherry picked from commit 3bc608a361a01043b226fb9aaebf88f6fd852925)
XQuartz: Avoid passing uninitialized pointers to X11ApplicationSetWindowMenu in AppleWMSetWindowMenu

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
(cherry picked from commit 77df653ae3d8448be21221711851acde12c6bc1a)
dix: fix button state check before changing a button mapping

dev->button->down is a bitmask, not a normal array. Use the helper function to
check, we technically allow the mapping to change after the physical button
has been pressed (but not yet processed yet), so only check BUTTON_PROCESSED.

From XSetPointerMapping(3):
"If any of the buttons to be altered are logically in the down state,
XSetPointerMapping returns MappingBusy, and the mapping is not changed."

Reported-by: Ilja Van Sprundel <ivansprundel@ioactive.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Daniel Stone <daniel@fooishbar.org>
(cherry picked from commit 25d10464f440b8b34594b7c988a99a830ea39a29)
Xi: Ensure DeviceChanged is emitted after grabs are deactivated

When a grab on a slave device is deactivated, the master device must
be checked, just in case there were events from other devices while
the slave device was stolen away by the passive grab. This may
introduce misbehaviors on mismatching valuators and device features
later on UpdateDeviceState().

Signed-off-by: Carlos Garnacho <carlosg@gnome.org>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
(cherry picked from commit b2d5ee2e3684951b611fd2068d57cc65fd8305a3)
os: restrict display names to digits

We call atoi() on the server's display to get the socket but otherwise use the
unmodified display for log file name, xkb paths, etc. This results in
Xorg :banana being the equivalent of Xorg :0, except for the log files being
in /var/log/Xorg.banana.log. I'm not sure there's a good use-case for this
behaviour.

Check the display for something that looks reasonable, i.e. digits only, but
do allow for :0.0 (i.e. digits, followed by a period, followed by one or two
digits).

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Keith Packard <keithp@keithp.com>
(cherry picked from commit 71baa466b1f6b02fe503f9a3089b7b9d61aa0f80)
Xi: fix modifier offset in XIPassiveGrab swapping function

The request is followed by mask_len 4-byte units, then followed by the actual
modifiers.

Also fix up the swapping test, which had the same issue.

Reported-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
(cherry picked from commit 76b3be75b62657e346731444736f7e4d200beb5b)

Conflicts:
	test/xi2/protocol-xipassivegrabdevice.c
Check for calloc() failure in add_master()

Reported-by: Ilja Van Sprundel <ivansprundel@ioactive.com>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
(cherry picked from commit 9fc19168e7ca6308275bf8769d1ccb982f88465b)
On realloc failure, free font_path_string instead of leaking it

Flagged by cppcheck 1.62:
[dix/dixfonts.c:1792]: (error) Common realloc mistake:
 'font_path_string' nulled but not freed upon failure

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Keith Packard <keithp@keithp.com>
(cherry picked from commit e6733ae91b7be52930f22a87de15fa05819ef948)
xf86DeleteScreen: move check for NULL pScrn before first dereference

Flagged by cppcheck 1.62:
[hw/xfree86/common/xf86Helper.c:220] -> [hw/xfree86/common/xf86Helper.c:231]:
 (warning) Possible null pointer dereference: pScrn - otherwise it is
 redundant to check it against null.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Keith Packard <keithp@keithp.com>
(cherry picked from commit c1ac89c793614797e08d3d8e7fc9ba55be899130)
dix: prevent a driver from initializing or submitting buttons > MAX_BUTTONS

The server internally relies on arrays with a MAX_BUTTONS maximum size (which
is the max the core protocol can transport). Make sure a driver adheres to
that.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Daniel Stone <daniel@fooishbar.org>
(cherry picked from commit 87ca80a7196949597113225405f3e4ee03bbee13)
Merge branch 'server-1.15-branch' of git://people.freedesktop.org/~jeremyhu/xserver into server-1.15-branch