adb: Use a default _SC_GETPW_R_SIZE_MAX size

sysconf(_SC_GETPW_R_SIZE_MAX) may return −1 if there is no hard limit
on the the buffer size. Some libc implementations such as musl don't
define this limit and will return -1.

Use a default buffer size to handle this case.

Change-Id: I997b13a2c2dca00574e049a259135e61c8ed8e03
Signed-off-by: Robert Yang <decatf@gmail.com>
This commit is contained in:
Robert Yang 2018-10-24 13:07:50 -04:00
parent ac305c82d6
commit 88c997d4eb

View file

@ -293,6 +293,9 @@ std::string adb_get_homedir_path() {
struct passwd pwent;
struct passwd* result;
int pwent_max = sysconf(_SC_GETPW_R_SIZE_MAX);
if (pwent_max == -1) {
pwent_max = 16384;
}
std::vector<char> buf(pwent_max);
int rc = getpwuid_r(getuid(), &pwent, buf.data(), buf.size(), &result);
if (rc == 0 && result) {