Skip to content

Commit

Permalink
Fixed system call for Sys::shellexec()
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed May 20, 2024
1 parent 68a7825 commit a300487
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/rishka_syscalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,14 @@ unsigned long RishkaSyscall::Sys::millisImpl() {
}

int64_t RishkaSyscall::Sys::shellExec(RishkaVM* parent_vm) {
auto program = parent_vm->getPointerParam<char*>(0);
auto argc = parent_vm->getParam<int>(1);
auto argv = parent_vm->getPointerParam<char**>(2);
auto cmdline = parent_vm->getPointerParam<char*>(0);

char* tokens[10];
int count = 0;

for(int i = 0; i < 10; i++)
tokens[i] = (char*) malloc(50 * sizeof(char));
rishka_split_cmd(String(cmdline), tokens, 10, count);

RishkaVM* child_vm = new RishkaVM();
child_vm->initialize(
Expand All @@ -176,14 +181,14 @@ int64_t RishkaSyscall::Sys::shellExec(RishkaVM* parent_vm) {
parent_vm->getWorkingDirectory()
);

if(!child_vm->loadFile(program)) {
if(!child_vm->loadFile(tokens[0])) {
child_vm->reset();
delete child_vm;

return -1;
}

child_vm->run(argc, argv);
child_vm->run(count, tokens + 1);
child_vm->reset();

int64_t exitCode = child_vm->getExitCode();
Expand Down

0 comments on commit a300487

Please sign in to comment.