mirror of
https://github.com/samba-team/samba.git
synced 2025-01-08 21:18:16 +03:00
util: Reallocate larger buffer if getpwuid_r() returns ERANGE
Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Volker Lendecke <vl@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
This commit is contained in:
parent
847208cd8a
commit
ddac6b2eb4
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user