Fix incorrect uses of getpwuid_r()

The function's behavior was recently fixed to succeed, but return a NULL
pointer, when the entry was not found. Fixes a crash in this case.
This commit is contained in:
Ingo Weinhold 2013-10-03 21:50:43 +02:00
parent 6bbd7bf3a0
commit 45b3329d9f
2 changed files with 5 additions and 3 deletions

View File

@ -400,8 +400,9 @@ Shell::_Spawn(int row, int col, const ShellParameters& parameters)
char stringBuffer[256];
if (argv == NULL || argc == 0) {
if (!getpwuid_r(getuid(), &passwdStruct, stringBuffer,
sizeof(stringBuffer), &passwdResult)) {
if (getpwuid_r(getuid(), &passwdStruct, stringBuffer,
sizeof(stringBuffer), &passwdResult) == 0
&& passwdResult != NULL) {
defaultArgs[0] = passwdStruct.pw_shell;
}

View File

@ -381,7 +381,8 @@ find_directory(directory_which which, dev_t device, bool createIt,
struct passwd *pw;
if (getpwuid_r(geteuid(), &pwBuffer, pwStringBuffer,
sizeof(pwStringBuffer), &pw) == 0) {
sizeof(pwStringBuffer), &pw) == 0
&& pw != NULL) {
home = pw->pw_dir;
}
#endif // USE_PWENTS