socket-util: check for sysconf() error before using value
Otherwise -1 will be casted to uint32_t. Found by coverity.
CID#1533989
Follow-up for 7e8aa5c2ee
This commit is contained in:
committed by
Luca Boccassi
parent
0fa25bd5f4
commit
9c41e4eb2f
@@ -930,13 +930,15 @@ int getpeersec(int fd, char **ret) {
|
||||
}
|
||||
|
||||
int getpeergroups(int fd, gid_t **ret) {
|
||||
socklen_t n = sizeof(gid_t) * 64U;
|
||||
_cleanup_free_ gid_t *d = NULL;
|
||||
|
||||
assert(fd >= 0);
|
||||
assert(ret);
|
||||
|
||||
long ngroups_max = sysconf(_SC_NGROUPS_MAX);
|
||||
socklen_t n = sizeof(gid_t) * MAX((socklen_t) ngroups_max, 64U);
|
||||
if (ngroups_max > 0)
|
||||
n = MAX(n, sizeof(gid_t) * (socklen_t) ngroups_max);
|
||||
|
||||
for (;;) {
|
||||
d = malloc(n);
|
||||
|
||||
Reference in New Issue
Block a user