r24750 by jghali - Fix potential buffer overflow + GS detection not working correctly with multiple GS installs

scribus-commit scribus-commit at lists.scribus.net
Mon Oct 25 19:39:25 UTC 2021


Author: jghali
Date: Mon Oct 25 19:39:25 2021
New Revision: 24750

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=24750
Log:
Fix potential buffer overflow + GS detection not working correctly with multiple GS installs

Modified:
    trunk/Scribus/scribus/util_ghostscript.cpp
    trunk/Scribus/scribus/util_os.cpp
    trunk/Scribus/scribus/util_os.h

Modified: trunk/Scribus/scribus/util_ghostscript.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24750&path=/trunk/Scribus/scribus/util_ghostscript.cpp
==============================================================================
--- trunk/Scribus/scribus/util_ghostscript.cpp	(original)
+++ trunk/Scribus/scribus/util_ghostscript.cpp	Mon Oct 25 19:39:25 2021
@@ -55,6 +55,7 @@
 #include "scribuscore.h"
 
 #include "util.h"
+#include "util_os.h"
 
 using namespace std;
 
@@ -249,7 +250,9 @@
 
 bool getNumericGSVersion(int &version)
 {
-	int gsMajor(0), gsMinor(0);
+	int gsMajor(0);
+	int gsMinor(0);
+
 	version = 0;
 	if (getNumericGSVersion(gsMajor, gsMinor))
 	{
@@ -287,13 +290,13 @@
 
 	// Test is we are running a 64bit version of WINDOWS
 	bool isWindows64 = false;
-	wchar_t* procArch = _wgetenv(L"PROCESSOR_ARCHITECTURE");
+	const wchar_t* procArch = _wgetenv(L"PROCESSOR_ARCHITECTURE");
 	if (procArch)
 	{
 		isWindows64 |= (wcscmp(procArch, L"AMD64") == 0);
 		isWindows64 |= (wcscmp(procArch, L"IA64") == 0);
 	}
-	wchar_t* procArchWow64 = _wgetenv(L"PROCESSOR_ARCHITEW6432");
+	const wchar_t* procArchWow64 = _wgetenv(L"PROCESSOR_ARCHITEW6432");
 	if (procArchWow64) isWindows64 = true;
 
 	// Search for Ghostsscript executable in native registry
@@ -360,10 +363,7 @@
 	WCHAR gsPath[MAX_PATH] = {};
 	QString gsVersion, gsExeName, gsName;
 
-	bool isWin64Api = false;
-#if defined(_WIN64)
-	isWin64Api = true;
-#endif
+	bool isWin64Api = os_is_win64();
 
 	gsExeName = isWin64Api ? "gswin64c.exe" : "gswin32c.exe";
 	if (alternateView)
@@ -374,7 +374,7 @@
 
 	if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, (LPCWSTR) regKey.utf16(), 0, flags, &hKey1) == ERROR_SUCCESS)
 	{
-		regVersionSize = sizeof(regVersion) / sizeof(WCHAR) - 1;
+		regVersionSize = sizeof(regVersion) / sizeof(WCHAR);
 		DWORD keyIndex = 0;
 		while (RegEnumKeyExW(hKey1, keyIndex, regVersion, &regVersionSize, nullptr, nullptr, nullptr, nullptr) == ERROR_SUCCESS)
 		{
@@ -407,6 +407,7 @@
 				}
 				RegCloseKey(hKey2);
 			}
+			regVersionSize = sizeof(regVersion) / sizeof(WCHAR);
 			keyIndex++;
 		}
 		RegCloseKey(hKey1);

Modified: trunk/Scribus/scribus/util_os.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24750&path=/trunk/Scribus/scribus/util_os.cpp
==============================================================================
--- trunk/Scribus/scribus/util_os.cpp	(original)
+++ trunk/Scribus/scribus/util_os.cpp	Mon Oct 25 19:39:25 2021
@@ -40,6 +40,15 @@
 #endif
 }
 
+bool os_is_win64()
+{
+#ifdef Q_OS_WIN64
+	return true;
+#else
+	return false;
+#endif
+}
+
 bool os_is_unix()
 {
 #ifdef Q_OS_UNIX

Modified: trunk/Scribus/scribus/util_os.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24750&path=/trunk/Scribus/scribus/util_os.h
==============================================================================
--- trunk/Scribus/scribus/util_os.h	(original)
+++ trunk/Scribus/scribus/util_os.h	Mon Oct 25 19:39:25 2021
@@ -12,6 +12,7 @@
 
 bool SCRIBUS_API os_is_osx();
 bool SCRIBUS_API os_is_win();
+bool SCRIBUS_API os_is_win64();
 bool SCRIBUS_API os_is_unix();
 
 #endif




More information about the scribus-commit mailing list