Don't leak addrinfo if ai->ai_addrlen <= minsiz test fails.
If the ai->ai_addrlen <= minsiz test fails, then freeaddrinfo() does not get called to free the memory just allocated by getaddrinfo(). Fix by moving ai->ai_addrlen <= minsiz to a separate nested if block, and keep freeaddrinfo() in the outer block so that freeaddrinfo() will be called whenever getaddrinfo() succeeds. Reported by: Coverity CID: 1273652 Reviewed by: ume MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D6756
This commit is contained in:
parent
eb49a6d366
commit
d7f12eacbb
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=301592
@ -411,20 +411,21 @@ __res_vinit(res_state statp, int preinit) {
|
||||
hints.ai_socktype = SOCK_DGRAM; /*dummy*/
|
||||
hints.ai_flags = AI_NUMERICHOST;
|
||||
sprintf(sbuf, "%u", NAMESERVER_PORT);
|
||||
if (getaddrinfo(cp, sbuf, &hints, &ai) == 0 &&
|
||||
ai->ai_addrlen <= minsiz) {
|
||||
if (statp->_u._ext.ext != NULL) {
|
||||
memcpy(&statp->_u._ext.ext->nsaddrs[nserv],
|
||||
ai->ai_addr, ai->ai_addrlen);
|
||||
if (getaddrinfo(cp, sbuf, &hints, &ai) == 0) {
|
||||
if (ai->ai_addrlen <= minsiz) {
|
||||
if (statp->_u._ext.ext != NULL) {
|
||||
memcpy(&statp->_u._ext.ext->nsaddrs[nserv],
|
||||
ai->ai_addr, ai->ai_addrlen);
|
||||
}
|
||||
if (ai->ai_addrlen <=
|
||||
sizeof(statp->nsaddr_list[nserv])) {
|
||||
memcpy(&statp->nsaddr_list[nserv],
|
||||
ai->ai_addr, ai->ai_addrlen);
|
||||
} else
|
||||
statp->nsaddr_list[nserv].sin_family = 0;
|
||||
nserv++;
|
||||
}
|
||||
if (ai->ai_addrlen <=
|
||||
sizeof(statp->nsaddr_list[nserv])) {
|
||||
memcpy(&statp->nsaddr_list[nserv],
|
||||
ai->ai_addr, ai->ai_addrlen);
|
||||
} else
|
||||
statp->nsaddr_list[nserv].sin_family = 0;
|
||||
freeaddrinfo(ai);
|
||||
nserv++;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
|
Loading…
Reference in New Issue
Block a user