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/parse.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/parse.cc') 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