зеркало из https://github.com/github/ruby.git
Check getlogin return value before passing to strcasecmp
getlogin can return NULL, and this can avoid a segfault in that case. Mentioned as an issue in comment to bug 20586.
This commit is contained in:
Родитель
8999fd1ac8
Коммит
ae886e0c83
3
file.c
3
file.c
|
@ -3706,6 +3706,7 @@ rb_home_dir_of(VALUE user, VALUE result)
|
|||
#else
|
||||
extern char *getlogin(void);
|
||||
const char *pwPtr = 0;
|
||||
const char *login;
|
||||
# define endpwent() ((void)0)
|
||||
#endif
|
||||
const char *dir, *username = RSTRING_PTR(user);
|
||||
|
@ -3722,7 +3723,7 @@ rb_home_dir_of(VALUE user, VALUE result)
|
|||
#ifdef HAVE_PWD_H
|
||||
pwPtr = (struct passwd *)IO_WITHOUT_GVL(nogvl_getpwnam, (void *)username);
|
||||
#else
|
||||
if (strcasecmp(username, getlogin()) == 0)
|
||||
if ((login = getlogin()) && strcasecmp(username, login) == 0)
|
||||
dir = pwPtr = getenv("HOME");
|
||||
#endif
|
||||
if (!pwPtr) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче