Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(RFC) Avoid possible null pointer dereference in setlisten() #1483

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions src/tcldcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ static int setlisten(Tcl_Interp *irp, char *ip, char *portp, char *type, char *m
struct portmap *pmap = NULL, *pold = NULL;
sockname_t name;
struct in_addr ipaddr4;
struct addrinfo hint, *ipaddr = NULL;
struct addrinfo hint, *res0 = NULL;
#ifdef IPV6
struct in6_addr ipaddr6;
#endif
Expand All @@ -1049,22 +1049,23 @@ static int setlisten(Tcl_Interp *irp, char *ip, char *portp, char *type, char *m
} else {
strlcpy(newip, ip, sizeof newip);
}
/* Return addrinfo struct ipaddr containing family... */
error = getaddrinfo(newip, NULL, &hint, &ipaddr);
/* Return addrinfo struct containing family... */
error = getaddrinfo(newip, NULL, &hint, &res0);
if (!error) {
/* Load network address to in(6)_addr struct for later byte comparisons */
if (ipaddr->ai_family == AF_INET) {
inet_pton(AF_INET, newip, &ipaddr4);
}
if (res0) {
/* Load network address to in(6)_addr struct for later byte comparisons */
if (res0->ai_family == AF_INET) {
inet_pton(AF_INET, newip, &ipaddr4);
}
#ifdef IPV6
else if (ipaddr->ai_family == AF_INET6) {
inet_pton(AF_INET6, newip, &ipaddr6);
ipv4 = 0;
}
else if (res0->ai_family == AF_INET6) {
inet_pton(AF_INET6, newip, &ipaddr6);
ipv4 = 0;
}
#endif
if (ipaddr) /* The behavior of freeadrinfo(NULL) is left unspecified by RFCs
* 2553 and 3493. Avoid to be compatible with all OSes. */
freeaddrinfo(ipaddr);
freeaddrinfo(res0);
} else
putlog(LOG_MISC, "*", "setlisten(): getaddrinfo() returned no address for ip %s", newip);
}
else if (error == EAI_NONAME)
/* currently setlisten() handles only ip not hostname */
Expand Down