mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-14 14:03:58 +00:00
lint: replace getpwname()
with getpwnam_r()
This commit is contained in:
parent
9b78857894
commit
a92a7cbb9c
2 changed files with 14 additions and 8 deletions
13
src/env.cpp
13
src/env.cpp
|
@ -840,16 +840,19 @@ void env_init(const struct config_paths_t *paths /* or NULL */) {
|
||||||
if (env_get_string(L"HOME").missing_or_empty()) {
|
if (env_get_string(L"HOME").missing_or_empty()) {
|
||||||
const env_var_t unam = env_get_string(L"USER");
|
const env_var_t unam = env_get_string(L"USER");
|
||||||
char *unam_narrow = wcs2str(unam.c_str());
|
char *unam_narrow = wcs2str(unam.c_str());
|
||||||
struct passwd *pw = getpwnam(unam_narrow);
|
struct passwd userinfo;
|
||||||
if (pw == NULL) {
|
struct passwd *result;
|
||||||
|
char buf[8192];
|
||||||
|
int retval = getpwnam_r(unam_narrow, &userinfo, buf, sizeof(buf), &result);
|
||||||
|
if (retval || !result) {
|
||||||
// Maybe USER is set but it's bogus. Reset USER from the db and try again.
|
// Maybe USER is set but it's bogus. Reset USER from the db and try again.
|
||||||
setup_user(true);
|
setup_user(true);
|
||||||
const env_var_t unam = env_get_string(L"USER");
|
const env_var_t unam = env_get_string(L"USER");
|
||||||
unam_narrow = wcs2str(unam.c_str());
|
unam_narrow = wcs2str(unam.c_str());
|
||||||
pw = getpwnam(unam_narrow);
|
retval = getpwnam_r(unam_narrow, &userinfo, buf, sizeof(buf), &result);
|
||||||
}
|
}
|
||||||
if (pw && pw->pw_dir) {
|
if (!retval && result && userinfo.pw_dir) {
|
||||||
const wcstring dir = str2wcstring(pw->pw_dir);
|
const wcstring dir = str2wcstring(userinfo.pw_dir);
|
||||||
env_set(L"HOME", dir.c_str(), ENV_GLOBAL | ENV_EXPORT);
|
env_set(L"HOME", dir.c_str(), ENV_GLOBAL | ENV_EXPORT);
|
||||||
}
|
}
|
||||||
free(unam_narrow);
|
free(unam_narrow);
|
||||||
|
|
|
@ -1178,11 +1178,14 @@ static void expand_home_directory(wcstring &input) {
|
||||||
} else {
|
} else {
|
||||||
// Some other users home directory.
|
// Some other users home directory.
|
||||||
std::string name_cstr = wcs2string(username);
|
std::string name_cstr = wcs2string(username);
|
||||||
struct passwd *userinfo = getpwnam(name_cstr.c_str());
|
struct passwd userinfo;
|
||||||
if (userinfo == NULL) {
|
struct passwd *result;
|
||||||
|
char buf[8192];
|
||||||
|
int retval = getpwnam_r(name_cstr.c_str(), &userinfo, buf, sizeof(buf), &result);
|
||||||
|
if (retval || !result) {
|
||||||
tilde_error = true;
|
tilde_error = true;
|
||||||
} else {
|
} else {
|
||||||
home = str2wcstring(userinfo->pw_dir);
|
home = str2wcstring(userinfo.pw_dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue