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

Fix xtreme8000#96 error when starting client with aos version in url #189

Open
wants to merge 3 commits into
base: standalone
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
28 changes: 18 additions & 10 deletions src/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -1008,16 +1008,24 @@ 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, ':');
*port_out = port_start ? strtoul(port_start + 1, NULL, 10) : 32887;

if(strchr(ip_start, '.')) {
if(port_start) {
strncpy(ip_out, ip_start, port_start - ip_start);
ip_out[port_start - ip_start] = 0;
} else {
strcpy(ip_out, ip_start);
}
} else {
// parse port, also ignore anything past another ':' (e.g. version info)
int next_colon = strchr(port_start + 1, ':');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is next_colon of type int even though strchr returns char*

*port_out = strtoul(port_start + 1, next_colon, 10);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

next_colon should be passed as a char** pointer, where strtoul can write the first invalid char pos to, HOWEVER we don't actually need it here, and can pass NULL instead, thus don't even need it in the first place

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this PR even do anything different to the original code, except the additional ip length check???


// if no port is specified (conversion fails), use default port
if(*port_out == 0)
*port_out = 32887;

int ip_length = port_start - ip_start;
if(ip_length > 32) {
return 0; // invalid ip
}

strncpy(ip_out, ip_start, ip_length);
ip_out[ip_length] = 0;

if(!strchr(ip_out, '.')) {
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);
}
Expand All @@ -1030,9 +1038,9 @@ int network_connect_string(char* addr) {
int port;
if(!network_identifier_split(addr, ip, &port))
return 0;

return network_connect(ip, port);
}

int network_update() {
if(network_connected) {
if(window_time() - network_stats_last >= 1.0F) {
Expand Down