From f099bb040c26708ecdb4f5e552843717caaba70b Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Thu, 9 Apr 2020 09:24:07 +0900 Subject: [PATCH] Ignore upper bits of pw_expire on macOS `pw_expire` is declared as `time_t`, but actually not, and `getpwuid` returns a garbage there. Also the declaration of `struct passwd` in pwd.h and the manual page contradict each other, interal `pw_fields` is mentioned only in the latter. Maybe there is a confusion. --- ext/etc/etc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ext/etc/etc.c b/ext/etc/etc.c index d57c26555b..5c08ba82ce 100644 --- a/ext/etc/etc.c +++ b/ext/etc/etc.c @@ -125,6 +125,12 @@ safe_setup_filesystem_str(const char *str) #endif #ifdef HAVE_GETPWENT +# ifdef __APPLE__ +# define PW_EXPIRE2VAL(t) INT2NUM((int)(t)) +# else +# define PW_EXPIRE2VAL(t) TIMET2NUM(t) +# endif + static VALUE setup_passwd(struct passwd *pwd) { @@ -157,7 +163,7 @@ setup_passwd(struct passwd *pwd) safe_setup_locale_str(pwd->pw_comment), #endif #ifdef HAVE_STRUCT_PASSWD_PW_EXPIRE - TIMET2NUM(pwd->pw_expire), + PW_EXPIRE2VAL(pwd->pw_expire), #endif 0 /*dummy*/ );