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
This commit is contained in:
Jake Turner
2021-07-12 19:26:20 +01:00
committed by Baldur Karlsson
parent 59ca2811ef
commit ee73091d54
2 changed files with 18 additions and 0 deletions
+13
View File
@@ -23,6 +23,7 @@
******************************************************************************/
#include "api/replay/rdcstr.h"
#include "common/common.h"
#import <Cocoa/Cocoa.h>
@@ -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;
+5
View File
@@ -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))
{