Skip to content

Commit

Permalink
env_get_runtime_path: Check for getpwuid() failure
Browse files Browse the repository at this point in the history
Otherwise this is a NULL dereference and then crash.

Fixes #5550.
  • Loading branch information
faho committed Jan 22, 2019
1 parent b23403e commit 82b4d72
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 82b4d72

Please sign in to comment.