mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-11-27 13:32:45 +00:00
MFC r301592
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 Differential Revision: https://reviews.freebsd.org/D6756
This commit is contained in:
parent
085483e827
commit
14b15f6ce4
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/stable/10/; revision=301920
@ -412,20 +412,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