aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-09-17 12:35:15 +0000
committer_ov4 <ov4@ov4.org>2026-09-17 12:35:15 +0000
commitf65446c93a8c033b704cac46c49bad92d72316d1 (patch)
tree45b515894e399d23a820bb4779ac45f68953b09b /src
parenta32a06c7cb257e254449919982ccb3d85c0bf0ca (diff)
fix stack size issue, replaced by heap
when input is too long, stack isn't large enough
Diffstat (limited to 'src')
-rw-r--r--src/eval.cc31
-rw-r--r--src/job.cc2
2 files changed, 18 insertions, 15 deletions
diff --git a/src/eval.cc b/src/eval.cc
index 716ca66..75c1d27 100644
--- a/src/eval.cc
+++ b/src/eval.cc
@@ -41,21 +41,24 @@ int eval_exe(const string &s, bool is_async, const T_lexer *lexer_instance, size
loggerln("eval_exe: receive {}", s);
bool task_type_is_subshell = false;
- char raw_input[MAXLINE];
- char **argv;
- char cmd_with_path[MAXLINE];
+ const char *raw_input = nullptr;
+ char **argv = nullptr;
+ const char *unified_cmd_c = nullptr;
+ string unified_cmd, s_wrap_eliminated;
// subshell type
if (lexer_instance != nullptr)
{
task_type_is_subshell = true;
- strcpy(raw_input, "SUBSHELL");
+ unified_cmd = "SUBSHELL";
+ raw_input = unified_cmd.c_str();
}
// command type
else
{
task_type_is_subshell = false;
- strcpy(raw_input, s.c_str());
+ s_wrap_eliminated = s.substr(0, s.find('\n')); // eliminate \n
+ raw_input = s_wrap_eliminated.c_str();
argv = parseline(s);
@@ -63,8 +66,8 @@ int eval_exe(const string &s, bool is_async, const T_lexer *lexer_instance, size
if (exe_bultin_command(argv)) return 0;
- string cmd = find_cmd(argv[0]);
- strcpy(cmd_with_path, cmd.c_str());
+ unified_cmd = find_cmd(argv[0]);
+ unified_cmd_c = unified_cmd.c_str();
}
// block_io signals can stop shell
@@ -97,43 +100,43 @@ int eval_exe(const string &s, bool is_async, const T_lexer *lexer_instance, size
}
// normal command
- execve(cmd_with_path, argv, environ);
+ execve(unified_cmd_c, argv, environ);
// execve: if success, never returns
- wrap_eliminator(raw_input);
cout << raw_input << flush;
switch (errno)
{
case ENOTDIR:
println(": A component of the path prefix is not a directory.");
- exit(errno);
+ _exit(errno);
break;
case ENAMETOOLONG:
println(": A component of a pathname exceeded 255 characters, or an entire path name exceeded 1023 characters.");
- exit(errno);
+ _exit(errno);
break;
case ENOENT:
println(": The new process file does not exist.");
- exit(errno);
+ _exit(errno);
break;
case EACCES:
println(": The new process file mode denies execute permission.");
- exit(errno);
+ _exit(errno);
break;
default:
println(": Error, code: {}", errno);
- exit(errno);
+ _exit(errno);
}
}
// parent
operator delete(argv);
+ argv = nullptr;
exit_required_pid = pid;
diff --git a/src/job.cc b/src/job.cc
index e4f9617..8e9e6cc 100644
--- a/src/job.cc
+++ b/src/job.cc
@@ -33,7 +33,7 @@ int maxjid(struct job_t *job)
}
/* addjob - Add a job to the job list */
-int addjob(pid_t pid, int state, char *cmdline, struct job_t *job)
+int addjob(pid_t pid, int state, const char *cmdline, struct job_t *job)
{
int i;