summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2020-06-05 22:05:42 +1000
committerKarolin Seeger <kseeger@samba.org>2020-07-06 09:06:23 +0000
commit016e08ca07f86af9e0131a908a2df116bcb9a48e (patch)
tree2d412358c2f3609cd2326cf4555cee4ec6f225c9
parent57bd719af1f138f44f71b2078995452582da0da6 (diff)
downloadsamba-016e08ca07f86af9e0131a908a2df116bcb9a48e.tar.gz
util: Reallocate larger buffer if getpwuid_r() returns ERANGE
Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Bjoern Jacke <bjacke@samba.org> Autobuild-User(master): Martin Schwenke <martins@samba.org> Autobuild-Date(master): Tue Jun 9 21:07:24 UTC 2020 on sn-devel-184 (cherry picked from commit ddac6b2eb4adaec8fc5e25ca07387d2b9417764c)
-rw-r--r--lib/util/util_paths.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/util/util_paths.c b/lib/util/util_paths.c
index 9bc6df37e5d..72cc0aab8de 100644
--- a/lib/util/util_paths.c
+++ b/lib/util/util_paths.c
@@ -86,6 +86,19 @@ static char *get_user_home_dir(TALLOC_CTX *mem_ctx)
}
rc = getpwuid_r(getuid(), &pwd, buf, len, &pwdbuf);
+ while (rc == ERANGE) {
+ size_t newlen = 2 * len;
+ if (newlen < len) {
+ /* Overflow */
+ goto done;
+ }
+ len = newlen;
+ buf = talloc_realloc_size(mem_ctx, buf, len);
+ if (buf == NULL) {
+ goto done;
+ }
+ rc = getpwuid_r(getuid(), &pwd, buf, len, &pwdbuf);
+ }
if (rc != 0 || pwdbuf == NULL ) {
const char *szPath = getenv("HOME");
if (szPath == NULL) {