From 8b133833fad05a0ea8fcc1282cc491d24865b897 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Sun, 17 Jan 2021 23:03:15 +0100 Subject: [PATCH] Don't inherit windows paths for $PWD If given a windows path like `F:\foo`, this currently ends up assert()ing in path_normalize_for_cd. Instead, since these paths violate a bunch of assumptions we make, we reject them and fall back on getting $PWD via getcwd() (which should give us a nice proper unixy path). Fixes #7636. This isn't tested because it would require a system where a windowsy path passes paths_are_same_file, and on the unix systems we run our tests that's impossible as far as I can tell? --- src/env.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/env.cpp b/src/env.cpp index ff13b6273..1a2bebaf7 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -363,9 +363,12 @@ void env_init(const struct config_paths_t *paths /* or NULL */) { // Note we may inherit a virtual PWD that doesn't match what getcwd would return; respect that // if and only if it matches getcwd (#5647). Note we treat PWD as read-only so it was not set in // vars. + // + // Also reject all paths that don't start with "/", this includes windows paths like "F:\foo". + // (see #7636) const char *incoming_pwd_cstr = getenv("PWD"); wcstring incoming_pwd = incoming_pwd_cstr ? str2wcstring(incoming_pwd_cstr) : wcstring{}; - if (!incoming_pwd.empty() && paths_are_same_file(incoming_pwd, L".")) { + if (!incoming_pwd.empty() && incoming_pwd.front() == L'/' && paths_are_same_file(incoming_pwd, L".")) { vars.set_one(L"PWD", ENV_EXPORT | ENV_GLOBAL, incoming_pwd); } else { vars.set_pwd_from_getcwd();