diff options
author | Ben Chan <benchan@chromium.org> | 2019-08-20 12:27:08 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-08-23 13:57:11 -0700 |
commit | b0ca3cd8c055a5090660955e3a1d3a1c849768a1 (patch) | |
tree | ddc27d60bfb10ac0b1cd3036277fa498efba95df | |
parent | ddb433c41731fa1dc251a8e6d3bcf170cad803c5 (diff) | |
download | platform_external_libbrillo-b0ca3cd8c055a5090660955e3a1d3a1c849768a1.tar.gz platform_external_libbrillo-b0ca3cd8c055a5090660955e3a1d3a1c849768a1.tar.bz2 platform_external_libbrillo-b0ca3cd8c055a5090660955e3a1d3a1c849768a1.zip |
libbrillo: handle EINTR on getpwnam_r() and getgrnam_r() calls
CL:1311594 incorrectly uses the HANDLE_EINTR() macro on getpwnam_r() and
getgrnam_r() to handle EINTR as the two functions actually return the
error number instead of setting errno. This CL fixes the EINTR handling
as well as the error message.
Reported-by: fdegros@chromium.org
BUG=None
TEST=Run unit tests.
Change-Id: I0f388b84a7cc38a0c7db1c67d9628024e87285b5
Reviewed-on: https://chromium-review.googlesource.com/1762631
Tested-by: Ben Chan <benchan@chromium.org>
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: François Degros <fdegros@chromium.org>
Cr-Mirrored-From: https://chromium.googlesource.com/chromiumos/platform2
Cr-Mirrored-Commit: 61a4b73ae52dcfdc44783d4a13ae2aff39f57840
-rw-r--r-- | brillo/userdb_utils.cc | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/brillo/userdb_utils.cc b/brillo/userdb_utils.cc index a204094..1308fb7 100644 --- a/brillo/userdb_utils.cc +++ b/brillo/userdb_utils.cc @@ -4,6 +4,7 @@ #include "brillo/userdb_utils.h" +#include <errno.h> #include <grp.h> #include <pwd.h> #include <sys/types.h> @@ -12,7 +13,7 @@ #include <vector> #include <base/logging.h> -#include <base/posix/eintr_wrapper.h> +#include <base/posix/safe_strerror.h> namespace brillo { namespace userdb { @@ -24,10 +25,16 @@ bool GetUserInfo(const std::string& user, uid_t* uid, gid_t* gid) { passwd pwd_buf; passwd* pwd = nullptr; std::vector<char> buf(buf_len); - if (HANDLE_EINTR( - getpwnam_r(user.c_str(), &pwd_buf, buf.data(), buf_len, &pwd)) || - !pwd) { - PLOG(ERROR) << "Unable to find user " << user; + + int err_num; + do { + err_num = getpwnam_r(user.c_str(), &pwd_buf, buf.data(), buf_len, &pwd); + } while (err_num == EINTR); + + if (!pwd) { + LOG(ERROR) << "Unable to find user " << user << ": " + << (err_num ? base::safe_strerror(err_num) + : "No matching record"); return false; } @@ -45,10 +52,16 @@ bool GetGroupInfo(const std::string& group, gid_t* gid) { struct group grp_buf; struct group* grp = nullptr; std::vector<char> buf(buf_len); - if (HANDLE_EINTR( - getgrnam_r(group.c_str(), &grp_buf, buf.data(), buf_len, &grp)) || - !grp) { - PLOG(ERROR) << "Unable to find group " << group; + + int err_num; + do { + err_num = getgrnam_r(group.c_str(), &grp_buf, buf.data(), buf_len, &grp); + } while (err_num == EINTR); + + if (!grp) { + LOG(ERROR) << "Unable to find group " << group << ": " + << (err_num ? base::safe_strerror(err_num) + : "No matching record"); return false; } |