From ee73091d5402a324f6fb9b5a54f1a30ba95c47e2 Mon Sep 17 00:00:00 2001 From: Jake Turner Date: Mon, 12 Jul 2021 19:26:20 +0100 Subject: [PATCH] Fix crash trying to capture invalid app name Before the code change this command renderdoccmd capture ~/dsdsds.app would trigger segmentation fault accessing a null pointer --- renderdoc/os/posix/apple/apple_helpers.mm | 13 +++++++++++++ renderdoc/os/posix/posix_process.cpp | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/renderdoc/os/posix/apple/apple_helpers.mm b/renderdoc/os/posix/apple/apple_helpers.mm index 8cc4c494c..8440a4215 100644 --- a/renderdoc/os/posix/apple/apple_helpers.mm +++ b/renderdoc/os/posix/apple/apple_helpers.mm @@ -23,6 +23,7 @@ ******************************************************************************/ #include "api/replay/rdcstr.h" +#include "common/common.h" #import @@ -62,8 +63,20 @@ bool apple_IsKeyPressed(int appleKeyCode) rdcstr apple_GetExecutablePathFromAppBundle(const char *appBundlePath) { NSString *path = [NSString stringWithCString:appBundlePath encoding:NSUTF8StringEncoding]; + NSBundle *nsBundle = [NSBundle bundleWithPath:path]; + if(!nsBundle) + { + RDCERR("Failed to open application '%s' as an NSBundle", appBundlePath); + return rdcstr(); + } + NSString *executablePath = nsBundle.executablePath; + if(!executablePath) + { + RDCERR("Failed to get executable path from application '%s'", appBundlePath); + return rdcstr(); + } rdcstr result([executablePath cStringUsingEncoding:NSUTF8StringEncoding]); return result; diff --git a/renderdoc/os/posix/posix_process.cpp b/renderdoc/os/posix/posix_process.cpp index c86703eb2..4b1edc62c 100644 --- a/renderdoc/os/posix/posix_process.cpp +++ b/renderdoc/os/posix/posix_process.cpp @@ -540,6 +540,11 @@ static pid_t RunProcess(rdcstr appName, rdcstr workDir, const rdcstr &cmdLine, c if(appName.size() > 5 && appName.endsWith(".app")) { rdcstr realAppName = apple_GetExecutablePathFromAppBundle(appName.c_str()); + if(realAppName.empty()) + { + RDCERR("Invalid application path '%s'", appName.c_str()); + return (pid_t)0; + } if(FileIO::exists(realAppName)) {