Skip to content

Commit

Permalink
fix port interpretation
Browse files Browse the repository at this point in the history
  • Loading branch information
kentslaney committed Dec 1, 2023
1 parent f486bb0 commit 89d3153
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,38 +56,54 @@ bool isLocalSocket(const char* host) {
return host[0] == '/';
}

void verifyPort(const char* input, ServerSpec* res, bool* valid_port) {
if (*valid_port && input > res->port) {
res->port[-1] = '\0';
} else if (res->alias == NULL) {
res->port = NULL;
}
*valid_port = false;
}

// modifies input string and output pointers reference input
ServerSpec splitServerString(char* input) {
bool escaped = false;
bool escaped = false, valid_port = false;
ServerSpec res = { input, NULL, NULL };
for (;; input++) {
switch (*input)
{
case '\0':
verifyPort(input, &res, &valid_port);
return res;
case ':': // invalid in a UNIX path
*input = '\0';
res.port = input + 1;
case ':':
if (res.alias == NULL) {
res.port = input + 1;
valid_port = true;
}
escaped = false;
continue;
case ' ':
if (!escaped) {
*input = '\0';
if (res.alias == NULL) {
res.alias = input + 1;
verifyPort(input, &res, &valid_port);
continue;
} else {
return res;
}
}
/* FALLTHROUGH */
default:
valid_port = false;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
escaped = false;
continue;
case '\\':
escaped ^= 1;
valid_port = false;
}
}
return res;
}

} // namespace mc
Expand Down

0 comments on commit 89d3153

Please sign in to comment.