summaryrefslogtreecommitdiff
path: root/Userland/Shell/Shell.cpp
diff options
context:
space:
mode:
authorsin-ack <sin-ack@users.noreply.github.com>2022-07-11 19:53:29 +0000
committerAndreas Kling <kling@serenityos.org>2022-07-12 23:11:35 +0200
commitc70f45ff4498fcb7ce0671e9107ecff8009d7eb2 (patch)
tree6250cc4ba6c43ed57639f3d7ff9c5fd34800989f /Userland/Shell/Shell.cpp
parente3da0adfe6d278424970dad5a642bda650737e42 (diff)
downloadserenity-c70f45ff4498fcb7ce0671e9107ecff8009d7eb2.zip
Everywhere: Explicitly specify the size in StringView constructors
This commit moves the length calculations out to be directly on the StringView users. This is an important step towards the goal of removing StringView(char const*), as it moves the responsibility of calculating the size of the string to the user of the StringView (which will prevent naive uses causing OOB access).
Diffstat (limited to 'Userland/Shell/Shell.cpp')
-rw-r--r--Userland/Shell/Shell.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/Userland/Shell/Shell.cpp b/Userland/Shell/Shell.cpp
index d1a39477a5..9f23e0cc93 100644
--- a/Userland/Shell/Shell.cpp
+++ b/Userland/Shell/Shell.cpp
@@ -110,7 +110,7 @@ String Shell::prompt() const
builder.append(username);
break;
case 'h':
- builder.append(hostname);
+ builder.append({ hostname, strlen(hostname) });
break;
case 'w': {
String home_path = getenv("HOME");
@@ -1607,7 +1607,7 @@ Vector<Line::CompletionSuggestion> Shell::complete_variable(StringView name, siz
// Look at the environment.
for (auto i = 0; environ[i]; ++i) {
- auto entry = StringView { environ[i] };
+ StringView entry { environ[i], strlen(environ[i]) };
if (entry.starts_with(pattern)) {
auto parts = entry.split_view('=');
if (parts.is_empty() || parts.first().is_empty())
@@ -2183,7 +2183,10 @@ Shell::Shell()
// Add the default PATH vars.
{
StringBuilder path;
- path.append(getenv("PATH"));
+ auto const* path_env_ptr = getenv("PATH");
+
+ if (path_env_ptr != NULL)
+ path.append({ path_env_ptr, strlen(path_env_ptr) });
if (path.length())
path.append(":");
path.append("/usr/local/sbin:/usr/local/bin:/usr/bin:/bin");
@@ -2476,7 +2479,8 @@ void Shell::timer_event(Core::TimerEvent& event)
if (m_is_subshell)
return;
- StringView option = getenv("HISTORY_AUTOSAVE_TIME_MS");
+ auto const* autosave_env_ptr = getenv("HISTORY_AUTOSAVE_TIME_MS");
+ auto option = autosave_env_ptr != NULL ? StringView { autosave_env_ptr, strlen(autosave_env_ptr) } : StringView {};
auto time = option.to_uint();
if (!time.has_value() || time.value() == 0) {