[Scummvm-git-logs] scummvm master -> e9e88003dc5903057cdcf7f6758e267485ee168b

bluegr noreply at scummvm.org
Sun Nov 5 09:45:41 UTC 2023


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
e9e88003dc SCI: Add sanity checks to SciEngine::errorString()


Commit: e9e88003dc5903057cdcf7f6758e267485ee168b
    https://github.com/scummvm/scummvm/commit/e9e88003dc5903057cdcf7f6758e267485ee168b
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2023-11-05T11:44:36+02:00

Commit Message:
SCI: Add sanity checks to SciEngine::errorString()

It would crash in errors thrown during resource loading

Changed paths:
    engines/sci/sci.cpp


diff --git a/engines/sci/sci.cpp b/engines/sci/sci.cpp
index 686965d973b..0e2f3a228d6 100644
--- a/engines/sci/sci.cpp
+++ b/engines/sci/sci.cpp
@@ -718,13 +718,13 @@ void SciEngine::runGame() {
 // When the SCI engine enters an error state, this block will add additional VM engine context for error reporting
 void SciEngine::errorString(const char *buf_input, char *buf_output, int buf_output_size) {
 	EngineState *s = _gamestate;
-	Script *sci = s->_segMan->getScriptIfLoaded(s->xs->addr.pc.getSegment());
+	Script *activeScript = (s && s->_segMan) ? s->_segMan->getScriptIfLoaded(s->xs->addr.pc.getSegment()) : nullptr;
+	Kernel *kernel = g_sci ? g_sci->getKernel() : nullptr;
 
 	// If a script is actively loaded at the time of error.
-	if (sci) {
+	if (activeScript && kernel) {
 		// Query the top-most stack frame even if it's not committed yet within the VM cycle.
 		const ExecStack *call = &(s->_executionStack.back());
-		Kernel *k = g_sci->getKernel();
 
 		// Note: if we are too early in the initialization process, this may not be populated yet.
 		const reg_t regVersion = s->variables[VAR_GLOBAL][kGlobalVarVersionNew];
@@ -738,16 +738,16 @@ void SciEngine::errorString(const char *buf_input, char *buf_output, int buf_out
 		switch (call->type) {
 		case EXEC_STACK_TYPE_CALL: // Normal function
 			callType = "selector";
-			callingFunc += Common::String::format("%s::%s", objname, k->getSelectorName(call->debugSelector).c_str());
+			callingFunc += Common::String::format("%s::%s", objname, kernel->getSelectorName(call->debugSelector).c_str());
 			pcStr = Common::String::format("%04x:%04x", PRINT_REG(call->addr.pc));
 			break;
 		case EXEC_STACK_TYPE_KERNEL: // Kernel function
 			if (call->debugKernelSubFunction == -1){
 				callType = "kernel";
-				callingFunc += Common::String::format("k%s(", k->getKernelName(call->debugKernelFunction).c_str());
+				callingFunc += Common::String::format("k%s(", kernel->getKernelName(call->debugKernelFunction).c_str());
 			} else {
 				callType = "subkernel";
-				callingFunc += Common::String::format("k%s(", k->getKernelName(call->debugKernelFunction, call->debugKernelSubFunction).c_str());
+				callingFunc += Common::String::format("k%s(", kernel->getKernelName(call->debugKernelFunction, call->debugKernelSubFunction).c_str());
 			}
 			pcStr = "none";
 			break;
@@ -763,13 +763,9 @@ void SciEngine::errorString(const char *buf_input, char *buf_output, int buf_out
 			pcStr.c_str());
 
 		snprintf(buf_output, buf_output_size, "%s\n%s", buf_input, errorStr.c_str());
-		
 	} else {
 		// VM not initialized yet, so just copy over the initial error.
-		strncpy(buf_output, buf_input, buf_output_size);
-		if (buf_output_size > 0) {
-			buf_output[buf_output_size - 1] = '\0';
-		}
+		Common::strlcpy(buf_output, buf_input, buf_output_size);
 	}
 }
 




More information about the Scummvm-git-logs mailing list