From 257b0fe4ebd01072be2725e0442091888ca7cf29 Mon Sep 17 00:00:00 2001 From: borgmanJeremy <46930769+borgmanJeremy@users.noreply.github.com> Date: Thu, 7 Apr 2022 09:00:58 -0500 Subject: [PATCH] fixed segfault when screen number exceeds screen count --- src/core/flameshot.cpp | 6 ++++++ src/main.cpp | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/core/flameshot.cpp b/src/core/flameshot.cpp index ae68cb5a01..196e878932 100644 --- a/src/core/flameshot.cpp +++ b/src/core/flameshot.cpp @@ -132,6 +132,7 @@ CaptureWidget* Flameshot::gui(const CaptureRequest& req) return m_captureWindow; } else { emit captureFailed(); + return nullptr; } } @@ -151,6 +152,11 @@ void Flameshot::screen(CaptureRequest req, const int screenNumber) screen = qApp->screens()[qApp->desktop()->screenNumber(globalCursorPos)]; #endif + } else if (screenNumber >= qApp->screens().count()) { + AbstractLogger() << QObject::tr( + "Requested screen exceeds screen count"); + emit captureFailed(); + return; } else { screen = qApp->screens()[screenNumber]; } diff --git a/src/main.cpp b/src/main.cpp index 500cf38c5d..1d4ddd1b03 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -442,7 +442,7 @@ int main(int argc, char* argv[]) QString numberStr = parser.value(screenNumberOption); // Option values - int number = + int screenNumber = numberStr.startsWith(QLatin1String("-")) ? -1 : numberStr.toInt(); QString path = parser.value(pathOption); if (!path.isEmpty()) { @@ -455,7 +455,7 @@ int main(int argc, char* argv[]) bool pin = parser.isSet(pinOption); bool upload = parser.isSet(uploadOption); - CaptureRequest req(CaptureRequest::SCREEN_MODE, delay, number); + CaptureRequest req(CaptureRequest::SCREEN_MODE, delay, screenNumber); if (!region.isEmpty()) { if (region.startsWith("screen")) { // TODO use abstract logger