From 0eab3508800445ae3cf31565bc5679aaaf5ac5ed Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 25 Jan 2022 09:56:31 +0100 Subject: [PATCH] Improve logging around screen resizing Avoid duplication, and add logging for some more error conditions so it's possible to see in the logs why a resize has failed or produced unexpected results. --- common/rfb/VNCSConnectionST.cxx | 13 +++++++++++-- common/rfb/VNCServerST.cxx | 8 ++++++-- unix/common/randr.cxx | 5 ++++- unix/x0vncserver/XDesktop.cxx | 6 ------ unix/xserver/hw/vnc/XserverDesktop.cc | 6 ------ 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx index f51fb57b..9f58e786 100644 --- a/common/rfb/VNCSConnectionST.cxx +++ b/common/rfb/VNCSConnectionST.cxx @@ -651,11 +651,20 @@ void VNCSConnectionST::setDesktopSize(int fb_width, int fb_height, const ScreenSet& layout) { unsigned int result; + char buffer[2048]; - if (!accessCheck(AccessSetDesktopSize) || !rfb::Server::acceptSetDesktopSize) + vlog.debug("Got request for framebuffer resize to %dx%d", + fb_width, fb_height); + layout.print(buffer, sizeof(buffer)); + vlog.debug("%s", buffer); + + if (!accessCheck(AccessSetDesktopSize) || + !rfb::Server::acceptSetDesktopSize) { + vlog.debug("Rejecting unauthorized framebuffer resize request"); result = resultProhibited; - else + } else { result = server->setDesktopSize(this, fb_width, fb_height, layout); + } writer()->writeDesktopSize(reasonClient, result); } diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx index 3a7caf5c..411cfd5e 100644 --- a/common/rfb/VNCServerST.cxx +++ b/common/rfb/VNCServerST.cxx @@ -539,12 +539,16 @@ unsigned int VNCServerST::setDesktopSize(VNCSConnectionST* requester, // We can't handle a framebuffer larger than this, so don't let a // client set one (see PixelBuffer.cxx) - if ((fb_width > 16384) || (fb_height > 16384)) + if ((fb_width > 16384) || (fb_height > 16384)) { + slog.error("Rejecting too large framebuffer resize request"); return resultProhibited; + } // Don't bother the desktop with an invalid configuration - if (!layout.validate(fb_width, fb_height)) + if (!layout.validate(fb_width, fb_height)) { + slog.error("Invalid screen layout requested by client"); return resultInvalid; + } // FIXME: the desktop will call back to VNCServerST and an extra set // of ExtendedDesktopSize messages will be sent. This is okay diff --git a/unix/common/randr.cxx b/unix/common/randr.cxx index 95c1f332..72b9a125 100644 --- a/unix/common/randr.cxx +++ b/unix/common/randr.cxx @@ -326,8 +326,11 @@ static unsigned int _setScreenLayout(bool dryrun, i = getPreferredScreenOutput(outputIdMap, disabledOutputs); /* Shouldn't happen */ - if (i == -1) + if (i == -1) { + if (logErrors) + vlog.error("Cannot find an available output for new screen layout"); return rfb::resultInvalid; + } output = vncRandRGetOutputId(i); /* diff --git a/unix/x0vncserver/XDesktop.cxx b/unix/x0vncserver/XDesktop.cxx index 351dbb2c..f2046e43 100644 --- a/unix/x0vncserver/XDesktop.cxx +++ b/unix/x0vncserver/XDesktop.cxx @@ -503,12 +503,6 @@ unsigned int XDesktop::setScreenLayout(int fb_width, int fb_height, const rfb::ScreenSet& layout) { #ifdef HAVE_XRANDR - char buffer[2048]; - vlog.debug("Got request for framebuffer resize to %dx%d", - fb_width, fb_height); - layout.print(buffer, sizeof(buffer)); - vlog.debug("%s", buffer); - XRRScreenResources *res = XRRGetScreenResources(dpy, DefaultRootWindow(dpy)); if (!res) { vlog.error("XRRGetScreenResources failed"); diff --git a/unix/xserver/hw/vnc/XserverDesktop.cc b/unix/xserver/hw/vnc/XserverDesktop.cc index 8a3cdb5c..603e1e5e 100644 --- a/unix/xserver/hw/vnc/XserverDesktop.cc +++ b/unix/xserver/hw/vnc/XserverDesktop.cc @@ -466,12 +466,6 @@ unsigned int XserverDesktop::setScreenLayout(int fb_width, int fb_height, { unsigned int result; - char buffer[2048]; - vlog.debug("Got request for framebuffer resize to %dx%d", - fb_width, fb_height); - layout.print(buffer, sizeof(buffer)); - vlog.debug("%s", buffer); - vncSetGlueContext(screenIndex); result = ::setScreenLayout(fb_width, fb_height, layout, &outputIdMap); -- 2.39.5