From 891f24c6521d8c84ab900810b85f41affba9a42e Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sat, 25 Jan 2020 23:05:14 +0100 Subject: Display.c: fix common realloc mistake As reported by static analyzer: (error) Common realloc mistake: 'nxagentVisuals' nulled but not freed upon failure --- nx-X11/programs/Xserver/hw/nxagent/Display.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'nx-X11/programs/Xserver/hw/nxagent/Display.c') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Display.c b/nx-X11/programs/Xserver/hw/nxagent/Display.c index c8ad891be..bc85d821d 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Display.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Display.c @@ -1494,8 +1494,13 @@ void nxagentInitVisuals(void) if (nxagentVisuals != NULL) { - nxagentVisuals = (XVisualInfo *) realloc(nxagentVisuals, - nxagentNumVisuals * sizeof(XVisualInfo)); + XVisualInfo *new = (XVisualInfo *) realloc(nxagentVisuals, + nxagentNumVisuals * sizeof(XVisualInfo)); + /* nxagentVisuals being NULL is covered below */ + if (new) + nxagentVisuals = new; + else + SAFE_free(nxagentVisuals); } SAFE_XFree(viList); -- cgit v1.2.3 From f09d3f52167c748083391bb489e591e78e494149 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sat, 25 Jan 2020 23:13:56 +0100 Subject: Display.c: fix implicit declaration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Display.c: In function ‘nxagentResetDisplayHandlers’: Display.c:901:5: warning: implicit declaration of function ‘nxagentReleaseAllSplits’; did you mean ‘nxagentWakeupBySplit’? [-Wimplicit-function-declaration] nxagentReleaseAllSplits(); ^~~~~~~~~~~~~~~~~~~~~~~ nxagentWakeupBySplit --- nx-X11/programs/Xserver/hw/nxagent/Display.c | 1 + 1 file changed, 1 insertion(+) (limited to 'nx-X11/programs/Xserver/hw/nxagent/Display.c') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Display.c b/nx-X11/programs/Xserver/hw/nxagent/Display.c index bc85d821d..e3221fb4e 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Display.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Display.c @@ -86,6 +86,7 @@ is" without express or implied warranty. #include "Splash.h" #include "Screen.h" #include "Handlers.h" +#include "Split.h" #include #include "compext/Compext.h" -- cgit v1.2.3 From d9e4526b388b23cda787cabe5d9aaf047cef075a Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Wed, 19 Feb 2020 22:48:12 +0100 Subject: Display.c: filter remote Pixmap formats before doing the compatiblity check Fixes: ArcticaProject/nx-libs#635 --- nx-X11/programs/Xserver/hw/nxagent/Display.c | 80 ++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 5 deletions(-) (limited to 'nx-X11/programs/Xserver/hw/nxagent/Display.c') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Display.c b/nx-X11/programs/Xserver/hw/nxagent/Display.c index e3221fb4e..55e40b461 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Display.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Display.c @@ -1553,6 +1553,7 @@ void nxagentInitPixmapFormats(void) */ nxagentNumPixmapFormats = 0; + nxagentRemoteNumPixmapFormats = 0; /* XXX: Some X server doesn't list 1 among available depths... @@ -1602,28 +1603,97 @@ XXX: Some X server doesn't list 1 among available depths... } } - nxagentRemotePixmapFormats = XListPixmapFormats(nxagentDisplay, &nxagentRemoteNumPixmapFormats); + /* + * we need to filter the list of remote pixmap formats by our + * supported depths, just like above. If we do not perform this step + * nxagentCheckForPixmapFormatsCompatibility will fail when + * tolerance is "strict" (the default). This becomes evident when + * Xephyr or Xnest are used as the real X server. They normally show + * only two supported depths but 7 supported pixmap formats (which + * could be a bug there). + */ + + int tmpnum = 0; + XPixmapFormatValues *tmp = XListPixmapFormats(nxagentDisplay, &tmpnum); - if (nxagentRemotePixmapFormats == NULL) + if (tmp == NULL) { #ifdef WARNING fprintf(stderr, "nxagentInitPixmapFormats: WARNING! Failed to get available remote pixmap formats.\n"); #endif + + nxagentRemotePixmapFormats = NULL; } - #ifdef TEST else { + #ifdef TEST fprintf(stderr, "nxagentInitPixmapFormats: Got [%d] available remote pixmap formats:\n", - nxagentRemoteNumPixmapFormats); + tmpnum); + + for (int i = 0; i < tmpnum; i++) + { + fprintf(stderr, "nxagentInitPixmapFormats: Found remote pixmap format [%d]: depth [%d] " + "bits_per_pixel [%d] scanline_pad [%d].\n", i, tmp[i].depth, + tmp[i].bits_per_pixel, tmp[i].scanline_pad); + } + #endif + + SAFE_XFree(tmp); + + nxagentRemotePixmapFormats = malloc((nxagentNumDepths + 1) * sizeof(XPixmapFormatValues)); + + for (int i = 1; i <= MAXDEPTH; i++) + { + int depth = 0; + + if (i == 1) + { + depth = 1; + } + else + { + for (int j = 0; j < nxagentNumDepths; j++) + { + if (nxagentDepths[j] == i) + { + depth = i; + break; + } + } + } + + if (depth != 0) + { + if (nxagentRemoteNumPixmapFormats >= MAXFORMATS) + { + FatalError("nxagentInitPixmapFormats: MAXFORMATS is too small for this remote server.\n"); + } + + nxagentRemotePixmapFormats[nxagentRemoteNumPixmapFormats].depth = depth; + nxagentRemotePixmapFormats[nxagentRemoteNumPixmapFormats].bits_per_pixel = nxagentBitsPerPixel(depth); + nxagentRemotePixmapFormats[nxagentRemoteNumPixmapFormats].scanline_pad = BITMAP_SCANLINE_PAD; + + #ifdef TEST + fprintf(stderr, "nxagentInitPixmapFormats: Suitable remote format [%d] to depth [%d] " + "bits per pixel [%d] scanline pad [%d].\n", nxagentRemoteNumPixmapFormats, + depth, nxagentRemotePixmapFormats[nxagentRemoteNumPixmapFormats].bits_per_pixel, + BITMAP_SCANLINE_PAD); + #endif + + nxagentRemoteNumPixmapFormats++; + } + } + + #ifdef TEST for (int i = 0; i < nxagentRemoteNumPixmapFormats; i++) { fprintf(stderr, "nxagentInitPixmapFormats: Remote pixmap format [%d]: depth [%d] " "bits_per_pixel [%d] scanline_pad [%d].\n", i, nxagentRemotePixmapFormats[i].depth, nxagentRemotePixmapFormats[i].bits_per_pixel, nxagentRemotePixmapFormats[i].scanline_pad); } + #endif } - #endif } void nxagentSetDefaultDrawables(void) -- cgit v1.2.3