From af69219a7229ccf524987123b2ecd70ff0456c9f Mon Sep 17 00:00:00 2001 From: _ov4 Date: Tue, 15 Sep 2026 01:41:50 +0000 Subject: fix string constucting from nullptr --- src/eval.cc | 2 ++ src/parse.cc | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/eval.cc b/src/eval.cc index 82bd09c..becad3b 100644 --- a/src/eval.cc +++ b/src/eval.cc @@ -31,6 +31,8 @@ namespace ov4 int eval_exe(string s, bool is_aync) { + loggerln("eval_exe: receive {}", s); + char cmdline[MAXLINE]; strcpy(cmdline, s.c_str()); char arg[MAXARGS][MAXLINE]; diff --git a/src/parse.cc b/src/parse.cc index 8480811..f61913a 100644 --- a/src/parse.cc +++ b/src/parse.cc @@ -19,7 +19,16 @@ int parseline(const char *cmdline, char **argv) int bg; /* background job? */ strcpy(buf, cmdline); - buf[strlen(buf)-1] = ' '; /* replace trailing '\n' with space */ + if (buf[strlen(buf)-1] == '\n') + buf[strlen(buf)-1] = ' '; /* replace trailing '\n' with space */ + else + { + // if buffer is not large enough + // might be UB + // TODO: fix UB + buf[strlen(buf)] = ' '; + buf[strlen(buf)+1] = '\0'; + } while (*buf && (*buf == ' ')) /* ignore leading spaces */ buf++; -- cgit v1.3.1-4-g156e