mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-15 14:34:05 +00:00
env_get_runtime_path: Check for getpwuid() failure
Otherwise this is a NULL dereference and then crash. Fixes #5550.
This commit is contained in:
parent
b23403ee6b
commit
82b4d7225c
1 changed files with 7 additions and 3 deletions
10
src/env.cpp
10
src/env.cpp
|
@ -1723,12 +1723,16 @@ wcstring env_get_runtime_path() {
|
|||
} else {
|
||||
// Don't rely on $USER being set, as setup_user() has not yet been called.
|
||||
// See https://github.com/fish-shell/fish-shell/issues/5180
|
||||
const char *uname = getpwuid(geteuid())->pw_name;
|
||||
// getpeuid() can't fail, but getpwuid sure can.
|
||||
auto pwuid = getpwuid(geteuid());
|
||||
const char *uname = pwuid ? pwuid->pw_name : NULL;
|
||||
// /tmp/fish.user
|
||||
std::string tmpdir = "/tmp/fish.";
|
||||
tmpdir.append(uname);
|
||||
if (uname) {
|
||||
tmpdir.append(uname);
|
||||
}
|
||||
|
||||
if (check_runtime_path(tmpdir.c_str()) != 0) {
|
||||
if (!uname || check_runtime_path(tmpdir.c_str()) != 0) {
|
||||
debug(0, L"Runtime path not available.");
|
||||
debug(0, L"Try deleting the directory %s and restarting fish.", tmpdir.c_str());
|
||||
return result;
|
||||
|
|
Loading…
Reference in a new issue