提交 c16888a8 编写于 作者: J Jim Meyering

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.
上级 1cb334ef
...@@ -2390,7 +2390,13 @@ int virGetUserID(virConnectPtr conn, ...@@ -2390,7 +2390,13 @@ int virGetUserID(virConnectPtr conn,
char *strbuf; char *strbuf;
struct passwd pwbuf; struct passwd pwbuf;
struct passwd *pw = NULL; 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) { if (VIR_ALLOC_N(strbuf, strbuflen) < 0) {
virReportOOMError(conn); virReportOOMError(conn);
...@@ -2427,7 +2433,13 @@ int virGetGroupID(virConnectPtr conn, ...@@ -2427,7 +2433,13 @@ int virGetGroupID(virConnectPtr conn,
char *strbuf; char *strbuf;
struct group grbuf; struct group grbuf;
struct group *gr = NULL; 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) { if (VIR_ALLOC_N(strbuf, strbuflen) < 0) {
virReportOOMError(conn); virReportOOMError(conn);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册