mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 19:48:20 +02:00
Fixed UseShellExecute flag when spawning a process
This commit is contained in:
parent
0aedc37d42
commit
9d1bd60c9a
2 changed files with 91 additions and 56 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -30,3 +30,5 @@ BeefPerf.txt
|
|||
IDE/Tests/Rando
|
||||
install/
|
||||
JEMalloc/
|
||||
.cache
|
||||
.vscode
|
|
@ -972,6 +972,9 @@ BFP_EXPORT BfpSpawn* BFP_CALLTYPE BfpSpawn_Create(const char* inTargetPath, cons
|
|||
}
|
||||
}
|
||||
|
||||
// When executing in a shell the arguments are not split
|
||||
if ((flags & BfpSpawnFlag_UseShellExecute) == 0)
|
||||
{
|
||||
int32 i = 0;
|
||||
for ( ; true; i++)
|
||||
{
|
||||
|
@ -1002,12 +1005,16 @@ BFP_EXPORT BfpSpawn* BFP_CALLTYPE BfpSpawn_Create(const char* inTargetPath, cons
|
|||
}
|
||||
if (firstCharIdx != -1)
|
||||
stringViews.Add(Beefy::StringView(args + firstCharIdx, i - firstCharIdx));
|
||||
}
|
||||
|
||||
Beefy::Array<char*> argvArr;
|
||||
|
||||
if ((flags & BfpSpawnFlag_ArgsIncludesTarget) == 0)
|
||||
if ((flags & BfpSpawnFlag_UseShellExecute) == 0 && (flags & BfpSpawnFlag_ArgsIncludesTarget) == 0)
|
||||
argvArr.Add(strdup(targetPath.c_str()));
|
||||
|
||||
// When executing in a shell the arguments are not split nor are the quotes removed
|
||||
if ((flags & BfpSpawnFlag_UseShellExecute) == 0)
|
||||
{
|
||||
for (int32 i = 0; i < (int32)stringViews.size(); i++)
|
||||
{
|
||||
Beefy::StringView stringView = stringViews[i];
|
||||
|
@ -1046,6 +1053,32 @@ BFP_EXPORT BfpSpawn* BFP_CALLTYPE BfpSpawn_Create(const char* inTargetPath, cons
|
|||
|
||||
argvArr.Add(str);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle shell execution
|
||||
if ((flags & BfpSpawnFlag_UseShellExecute) != 0)
|
||||
{
|
||||
// Create command string
|
||||
int argsLength = strlen(args);
|
||||
int length = targetPath.mLength + 1 + argsLength;
|
||||
|
||||
char* commandStr = (char*)malloc(length + 1);
|
||||
|
||||
memcpy(commandStr, targetPath.c_str(), targetPath.mLength);
|
||||
commandStr[targetPath.mLength] = ' ';
|
||||
memcpy(&commandStr[targetPath.mLength + 1], args, argsLength);
|
||||
commandStr[length] = '\0';
|
||||
|
||||
// Replace target path
|
||||
targetPath.Clear();
|
||||
targetPath.Append("/bin/sh");
|
||||
|
||||
// Add arguments
|
||||
argvArr.Add(strdup("sh"));
|
||||
argvArr.Add(strdup("-c"));
|
||||
argvArr.Add(commandStr);
|
||||
}
|
||||
|
||||
argvArr.Add(NULL);
|
||||
|
||||
char** argv = NULL;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue