Skip to content

Commit

Permalink
Fix signed integer overflow causing wrong ip
Browse files Browse the repository at this point in the history
  • Loading branch information
xtreme8000 committed Nov 10, 2018
1 parent a5ce575 commit e76d5fb
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/network.c
Expand Up @@ -961,23 +961,16 @@ int network_identifier_split(char* addr, char* ip_out, int* port_out) {
if((size_t)ip_start<=6)
return 0;
char* port_start = strchr(ip_start,':');
if(port_start)
*port_start = 0;

if(strchr(ip_start,'.')) {
*port_out = port_start?atoi(port_start+1):32887;
*port_out = port_start?strtoul(port_start+1,NULL,10):32887;
strcpy(ip_out,ip_start);
} else {
int ip = atoi(ip_start);
char ip_str[32];
sprintf(ip_str,"%i.%i.%i.%i",ip&255,(ip>>8)&255,(ip>>16)&255,(ip>>24)&255);

*port_out = port_start?atoi(port_start+1):32887;
strcpy(ip_out,ip_str);
unsigned int ip = strtoul(ip_start,NULL,10);
sprintf(ip_out,"%i.%i.%i.%i",ip&255,(ip>>8)&255,(ip>>16)&255,(ip>>24)&255);
*port_out = port_start?strtoul(port_start+1,NULL,10):32887;
}

if(port_start)
*port_start = ':';
return 1;
}

Expand Down

0 comments on commit e76d5fb

Please sign in to comment.