diff options
author | Luke Bratch <luke@bratch.co.uk> | 2021-01-25 21:54:20 +0000 |
---|---|---|
committer | Luke Bratch <luke@bratch.co.uk> | 2021-01-25 21:54:20 +0000 |
commit | 91c030f3831f79e41aa5718c4b543c242fa1b880 (patch) | |
tree | 1746709560004484e70d8f21476932c89c092c78 | |
parent | 4b282dd670c7263232d19412f9735d670a1b1b76 (diff) |
Use a space followed by a colon to determine the final parameter in extractfinalparameter().
This fixes the topic being stored incorrectly when the setter's host is a raw IPv6 address.
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | functions.c | 27 |
2 files changed, 17 insertions, 12 deletions
@@ -16,6 +16,4 @@ Ability to load new certificate whilst running. Are any other strncmps incorrect (i.e. just checking a substring)? -Topic is stored incorrectly when the setter's host was an IPv6 address (colon search issue?). - Crash when requesting 30 hour replay. diff --git a/functions.c b/functions.c index e89d836..7184bfa 100644 --- a/functions.c +++ b/functions.c @@ -213,15 +213,19 @@ void stripprefix(char *string, int debug) { } // Extract final parameter from IRC message, removing the leading colon ':' -// e.g. given this string: -// ":irc.tghost.co.uk 332 blabounce #test :This is a test topic!" +// e.g. given either of these strings: +// ":irc.tghost.co.uk 332 blabounce #test :foo:bar topic!" +// ":nick!user@fe80:1:2:3:5:6:7:8 TOPIC #test :foo:bar topic!" // We want to end up with: -// "This is a test topic!" +// "foo:bar topic!" void extractfinalparameter(char *string) { + // The method used is to look for the first space (" ") followed by a colon (":") + // and take everything after that colon as the final parameter. + // Make a copy to work with char string2[strlen(string)]; - // Position of colon + // Position of final parameter's leading colon int colonpos = -1; debugprint(DEBUG_FULL, "extractfinalparameter(): starting with '%s', strlen: %zd.\n", string, strlen(string)); @@ -229,17 +233,20 @@ void extractfinalparameter(char *string) { // Strip the colon at position 0 if there is one stripprefix(string, 1); - // Find the colon + // Look for spaces... for (size_t i = 0; i < strlen(string); i++) { - if (string[i] == ':') { - debugprint(DEBUG_FULL, "Found colon at position %zd!\n", i); - colonpos = i; - break; + if (string[i] == ' ') { + debugprint(DEBUG_FULL, "extractfinalparameter(): found space at position %zd! Checking for colon...\n", i); + // ...and check if the next character is a colon + if (string[i + 1] == ':') { + colonpos = i + 1; + break; + } } } if (colonpos == -1) { - debugprint(DEBUG_FULL, "no colon found, returning\n"); + debugprint(DEBUG_SOME, "extractfinalparameter(): no space followed by a colon found, returning.\n"); return; } |