You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by ar...@apache.org on 2025/12/06 18:00:32 UTC

(openoffice) 01/01: Catch invalid parameters detected by the Win32 runtime library

This is an automated email from the ASF dual-hosted git repository.

ardovm pushed a commit to branch win32invalidparameter
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit 5251883afdfa7aed488bbefaf25b140b52763fc8
Author: Arrigo Marchiori <ar...@yahoo.it>
AuthorDate: Sat Dec 6 18:58:36 2025 +0100

    Catch invalid parameters detected by the Win32 runtime library
---
 main/sal/osl/w32/signal.cxx | 47 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/main/sal/osl/w32/signal.cxx b/main/sal/osl/w32/signal.cxx
index 698d3612a1..96720250aa 100644
--- a/main/sal/osl/w32/signal.cxx
+++ b/main/sal/osl/w32/signal.cxx
@@ -51,6 +51,14 @@ static oslSignalHandlerImpl*  SignalList;
 
 static long WINAPI SignalHandlerFunction(LPEXCEPTION_POINTERS lpEP);
 
+static _invalid_parameter_handler pPreviousInvalidParameterHandler = NULL;
+static void InvalidParameterHandlerFunction(
+	const wchar_t* expression,
+	const wchar_t* function,
+	const wchar_t* file,
+	unsigned int line,
+	uintptr_t pReserved );
+
 static sal_Bool InitSignal(void)
 {
 	HMODULE	hFaultRep;
@@ -58,6 +66,10 @@ static sal_Bool InitSignal(void)
 	SignalListMutex = osl_createMutex();
 
 	SetUnhandledExceptionFilter(SignalHandlerFunction);
+	if ( pPreviousInvalidParameterHandler == NULL )
+	{
+		pPreviousInvalidParameterHandler = _set_invalid_parameter_handler( InvalidParameterHandlerFunction );
+	}
 
 	hFaultRep = LoadLibrary( "faultrep.dll" );
 	if ( hFaultRep )
@@ -78,6 +90,11 @@ static sal_Bool DeInitSignal(void)
 {
 	SetUnhandledExceptionFilter(NULL);
 
+	if ( pPreviousInvalidParameterHandler )
+	{
+		_set_invalid_parameter_handler( pPreviousInvalidParameterHandler );
+		pPreviousInvalidParameterHandler = NULL;
+	}
 	osl_destroyMutex(SignalListMutex);
 
 	return sal_False;
@@ -320,6 +337,36 @@ static long WINAPI SignalHandlerFunction(LPEXCEPTION_POINTERS lpEP)
 	return (EXCEPTION_CONTINUE_EXECUTION);
 }
 
+static void InvalidParameterHandlerFunction(
+	const wchar_t* expression,
+	const wchar_t* function,
+	const wchar_t* file,
+	unsigned int line,
+	uintptr_t pReserved )
+{
+	oslSignalInfo	Info;
+
+	fwprintf(stderr, L"Invalid parameter detected in function %s.\n"
+			 L"File: %s\n"
+			 L"Line: %u\n"
+			 L"Expression: %s\n"
+			 L"pReserved: %p\n", function, file, line, expression, pReserved);
+
+	Info.Signal = osl_Signal_AccessViolation;
+	Info.UserSignal = 0;
+	Info.UserData = NULL;
+	if ( ReportCrash( NULL ) || IsWin95A() )
+	{
+		CallSignalHandler(&Info);
+		abort(); // Equivalent of osl_Signal_ActAbortApp
+	} else {
+		// Equivalent of osl_Signal_ActKillApp
+		SetErrorMode(SEM_NOGPFAULTERRORBOX);
+		exit(255);
+	}
+	// We will never reach this point
+}
+
 /*****************************************************************************/
 /* osl_addSignalHandler */
 /*****************************************************************************/