mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 22:25:25 +00:00
util.c (two more): don't use a negative value as allocation size
* src/util/util.c (virGetUserID, virGetGroupID): In the unlikely event that sysconf(_SC_GETPW_R_SIZE_MAX) fails, don't use -1 as the size in the subsequent allocation.
This commit is contained in:
parent
1cb334efba
commit
c16888a849
@ -2390,7 +2390,13 @@ int virGetUserID(virConnectPtr conn,
|
||||
char *strbuf;
|
||||
struct passwd pwbuf;
|
||||
struct passwd *pw = NULL;
|
||||
size_t strbuflen = sysconf(_SC_GETPW_R_SIZE_MAX);
|
||||
long val = sysconf(_SC_GETPW_R_SIZE_MAX);
|
||||
size_t strbuflen = val;
|
||||
|
||||
if (val < 0) {
|
||||
virReportSystemError(conn, errno, "%s", _("sysconf failed"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC_N(strbuf, strbuflen) < 0) {
|
||||
virReportOOMError(conn);
|
||||
@ -2427,7 +2433,13 @@ int virGetGroupID(virConnectPtr conn,
|
||||
char *strbuf;
|
||||
struct group grbuf;
|
||||
struct group *gr = NULL;
|
||||
size_t strbuflen = sysconf(_SC_GETGR_R_SIZE_MAX);
|
||||
long val = sysconf(_SC_GETGR_R_SIZE_MAX);
|
||||
size_t strbuflen = val;
|
||||
|
||||
if (val < 0) {
|
||||
virReportSystemError(conn, errno, "%s", _("sysconf failed"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC_N(strbuf, strbuflen) < 0) {
|
||||
virReportOOMError(conn);
|
||||
|
Loading…
Reference in New Issue
Block a user