Skip to content

Commit

Permalink
Don't rely on getlogin() for getting usernames.
Browse files Browse the repository at this point in the history
In some cases this will, for whatever reason, return NULL. As a result the fsapi
path ends up being NULL terminated. This results in any following data being
ignored by whatever uses the path. This caused the console to use paths such as
"/tmp/rbx-/console-response" instead of
"/tmp/rbx-yorickpeterse-XXX/console-response".
Yorick Peterse committed Oct 16, 2014
1 parent c8dde0e commit 808e0f3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion vm/environment.cpp
Original file line number Diff line number Diff line change
@@ -57,6 +57,7 @@
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <pwd.h>

#include "missing/setproctitle.h"

@@ -311,6 +312,7 @@ namespace rubinius {

void Environment::set_fsapi_path() {
std::ostringstream path;
struct passwd *user_passwd = getpwuid(getuid());

if(!config.system_fsapi_path.value.compare("$TMPDIR")) {
path << config.system_tmp.value;
@@ -321,7 +323,8 @@ namespace rubinius {
if(cpath[cpath.size() - 1] != '/') path << "/";
}

path << "rbx-" << getlogin() << "-" << getpid();
path << "rbx-" << user_passwd->pw_name << "-" << getpid();

shared->fsapi_path.assign(path.str());

create_fsapi(state);

0 comments on commit 808e0f3

Please sign in to comment.