Skip to content
Permalink
Browse files

Fix inet_pton error

Found by: tabb
Patch by: michaelortmann

* Fix inet_pton input bug from #783
  • Loading branch information...
michaelortmann authored and vanosg committed Sep 17, 2019
1 parent 86ee5dd commit 3ad1b7be4f6ab86d657ff8ddcce5aab1c719776e
Showing with 19 additions and 2 deletions.
  1. +19 −2 src/net.c
@@ -130,11 +130,30 @@ char *iptostr(struct sockaddr *sa)
*/
int setsockname(sockname_t *addr, char *src, int port, int allowres)
{
char *endptr;
long val;
IP ip;
struct hostent *hp;
int af = AF_UNSPEC;
#ifdef IPV6
char ip2[INET6_ADDRSTRLEN];
int pref;
#else
char ip2[INET_ADDRSTRLEN];
int i, count;
#endif

/* DCC CHAT ip is expressed as integer but inet_pton() only accepts dotted
* addresses */
val = strtol(src, &endptr, 10);
if (val && !*endptr) {
ip = htonl(val);
if (inet_ntop(AF_INET, &ip, ip2, sizeof ip2)) {
debug2("net: setsockname(): ip %s -> %s", src, ip2);
src = ip2;
}
}
#ifdef IPV6
/* Clean start */
egg_bzero(addr, sizeof(sockname_t));
pref = pref_af ? AF_INET6 : AF_INET;
@@ -185,8 +204,6 @@ int setsockname(sockname_t *addr, char *src, int port, int allowres)
addr->addr.s4.sin_family = AF_INET;
}
#else
int i, count;

egg_bzero(addr, sizeof(sockname_t));

/* If it's not an IPv4 address, check if its IPv6 (so it can fail/error

0 comments on commit 3ad1b7b

Please sign in to comment.
You can’t perform that action at this time.