From 88c997d4eb6f66f9b52e56668cbdf48f5c99e183 Mon Sep 17 00:00:00 2001 From: Robert Yang Date: Wed, 24 Oct 2018 13:07:50 -0400 Subject: [PATCH] adb: Use a default _SC_GETPW_R_SIZE_MAX size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- adb/adb_utils.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/adb/adb_utils.cpp b/adb/adb_utils.cpp index ad7706466..69603455a 100644 --- a/adb/adb_utils.cpp +++ b/adb/adb_utils.cpp @@ -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 buf(pwent_max); int rc = getpwuid_r(getuid(), &pwent, buf.data(), buf.size(), &result); if (rc == 0 && result) {