From 37f4a7db93362440aad70e4d57e0f8721d09e5cd Mon Sep 17 00:00:00 2001 From: Stas Sergeev Date: Mon, 3 Mar 2025 00:18:28 +0300 Subject: [PATCH] add checks before accessing argv[0] This makes comcom64 compatible with silly -l loader that doesn't support args. See https://github.com/dosemu2/dosemu2/issues/2398 --- src/command.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/command.c b/src/command.c index 6c3cc87..c421a20 100644 --- a/src/command.c +++ b/src/command.c @@ -4644,7 +4644,7 @@ void do_int0(void) int main(int argc, const char *argv[], const char *envp[]) { int a; - char *cmd_path, *v; + char *v; int disable_autoexec = 0; int inited = 0; // initialize the cmd data ... @@ -4672,12 +4672,14 @@ int main(int argc, const char *argv[], const char *envp[]) // init bat file stack reset_batfile_call_stack(); - - cmd_path = strdup(argv[0]); - strupr(cmd_path); - conv_unix_path_to_ms_dos(cmd_path); - setenv("COMSPEC", cmd_path, 1); - free(cmd_path); + if (argc > 0 && !getenv("COMSPEC")) + { + char *cmd_path = strdup(argv[0]); + strupr(cmd_path); + conv_unix_path_to_ms_dos(cmd_path); + setenv("COMSPEC", cmd_path, 1); + free(cmd_path); + } setenv("COMCOM_VER", version, 1); setenv("ERRORLEVEL", "0", 1); setenv("TERM", "djgpp", 0);