Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/libcrun/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,6 @@ set_home_env (uid_t id)
cleanup_free char *buf = NULL;
long buf_size;
cleanup_file FILE *stream = NULL;
int ret = -1;

buf_size = sysconf (_SC_GETPW_R_SIZE_MAX);
if (buf_size < 0)
Expand All @@ -1463,11 +1462,15 @@ set_home_env (uid_t id)
{
struct passwd *ret_pw = NULL;

ret = fgetpwent_r (stream, &pwd, buf, buf_size, &ret_pw);
int ret = fgetpwent_r (stream, &pwd, buf, buf_size, &ret_pw);
if (UNLIKELY (ret != 0))
{
if (errno != ERANGE)
goto error;
if (ret != ERANGE)
{
/* Let callers handle the error if the user was not found. */
errno = ret;
goto error;
}

buf_size *= 2;
buf = xrealloc (buf, buf_size);
Expand All @@ -1482,8 +1485,7 @@ set_home_env (uid_t id)
}

error:
/* Let callers handle the error if the user was not found. */
return ret ? -errno : 0;
return -errno;
}

/*if subuid or subgid exist, take the first range for the user */
Expand Down