From a606c3187be900ae0f43b2bba650a900bd500de0 Mon Sep 17 00:00:00 2001 From: Jacob Trimble Date: Fri, 27 Jul 2018 10:45:43 -0700 Subject: [PATCH] Allow getpwuid_r to return missing entry. If the getpwuid_r method doesn't find an entry with the given ID, it will still return success (0), but the *result will be set to NULL. This checks the |result| value so it won't crash if it doesn't find the entry. This normally shouldn't ever happen, but it can somehow happen on iOS simulators. --- CONTRIBUTORS | 1 + src/utilities.cc | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 432e91b..5cbbce4 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -31,6 +31,7 @@ Fumitoshi Ukai Guillaume Dumont HÃ¥kan L. S. Younes Ivan Penkov +Jacob Trimble Jim Ray Michael Tanner MiniLight diff --git a/src/utilities.cc b/src/utilities.cc index 25c4b76..71f71e6 100644 --- a/src/utilities.cc +++ b/src/utilities.cc @@ -311,7 +311,7 @@ static void MyUserNameInitializer() { char buffer[1024] = {'\0'}; uid_t uid = geteuid(); int pwuid_res = getpwuid_r(uid, &pwd, buffer, sizeof(buffer), &result); - if (pwuid_res == 0) { + if (pwuid_res == 0 && result) { g_my_user_name = pwd.pw_name; } else { snprintf(buffer, sizeof(buffer), "uid%d", uid);