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:
Jim Meyering 2010-02-01 21:45:06 +01:00
parent 1cb334efba
commit c16888a849

View File

@ -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);