Tighten IRCv3 STS spec handling

This commit is contained in:
2026-03-24 08:49:27 -06:00
parent ec5e38d1f9
commit fc90fd41be
4 changed files with 50 additions and 5 deletions

View File

@@ -1796,6 +1796,36 @@ inbound_cap_ack (server *serv, char *nick, char *extensions,
inbound_toggle_caps (serv, extensions, TRUE); inbound_toggle_caps (serv, extensions, TRUE);
} }
void
inbound_cap_new (server *serv, char *nick, char *extensions,
const message_tags_data *tags_data)
{
if (extensions)
{
char **tokens = g_strsplit (extensions, " ", 0);
int i;
for (i = 0; tokens[i]; i++)
{
char **parts = g_strsplit (tokens[i], "=", 2);
if (!g_strcmp0 (parts[0], "sts") && parts[1] && parts[1][0])
{
sts_handle_capability (serv, parts[1]);
}
g_strfreev (parts);
}
g_strfreev (tokens);
}
EMIT_SIGNAL_TIMESTAMP (XP_TE_CAPACK, serv->server_session, nick, extensions,
NULL, NULL, 0, tags_data->timestamp);
inbound_toggle_caps (serv, extensions, TRUE);
}
void void
inbound_cap_del (server *serv, char *nick, char *extensions, inbound_cap_del (server *serv, char *nick, char *extensions,
const message_tags_data *tags_data) const message_tags_data *tags_data)

View File

@@ -95,6 +95,8 @@ void inbound_cap_ls (server *serv, char *nick, char *extensions,
void inbound_cap_nak (server *serv, char *extensions, const message_tags_data *tags_data); void inbound_cap_nak (server *serv, char *extensions, const message_tags_data *tags_data);
void inbound_cap_list (server *serv, char *nick, char *extensions, void inbound_cap_list (server *serv, char *nick, char *extensions,
const message_tags_data *tags_data); const message_tags_data *tags_data);
void inbound_cap_new (server *serv, char *nick, char *extensions,
const message_tags_data *tags_data);
void inbound_cap_del (server *serv, char *nick, char *extensions, void inbound_cap_del (server *serv, char *nick, char *extensions,
const message_tags_data *tags_data); const message_tags_data *tags_data);
void inbound_sasl_authenticate (server *serv, char *data); void inbound_sasl_authenticate (server *serv, char *data);

View File

@@ -1359,12 +1359,18 @@ process_named_msg (session *sess, char *type, char *word[], char *word_eol[],
word[5][0] == ':' ? word_eol[5] + 1 : word_eol[5], word[5][0] == ':' ? word_eol[5] + 1 : word_eol[5],
tags_data); tags_data);
} }
else if (g_ascii_strncasecmp(word[4], "LS", 2) == 0 || g_ascii_strncasecmp(word[4], "NEW", 3) == 0) else if (g_ascii_strncasecmp(word[4], "LS", 2) == 0)
{ {
inbound_cap_ls (serv, word[1], inbound_cap_ls (serv, word[1],
word[5][0] == ':' ? word_eol[5] + 1 : word_eol[5], word[5][0] == ':' ? word_eol[5] + 1 : word_eol[5],
tags_data); tags_data);
} }
else if (g_ascii_strncasecmp(word[4], "NEW", 3) == 0)
{
inbound_cap_new (serv, word[1],
word[5][0] == ':' ? word_eol[5] + 1 : word_eol[5],
tags_data);
}
else if (g_ascii_strncasecmp(word[4], "NAK", 3) == 0) else if (g_ascii_strncasecmp(word[4], "NAK", 3) == 0)
{ {
inbound_cap_nak (serv, word[5][0] == ':' ? word_eol[5] + 1 : word_eol[5], tags_data); inbound_cap_nak (serv, word[5][0] == ':' ? word_eol[5] + 1 : word_eol[5], tags_data);

View File

@@ -305,6 +305,7 @@ sts_parse_value (const char *value, guint16 *port, guint64 *duration, gboolean *
{ {
char **tokens; char **tokens;
gsize i; gsize i;
char *end;
if (!value || !*value) if (!value || !*value)
{ {
@@ -349,8 +350,9 @@ sts_parse_value (const char *value, guint16 *port, guint64 *duration, gboolean *
continue; continue;
} }
port_value = g_ascii_strtoll (val, NULL, 10); end = NULL;
if (port_value > 0 && port_value <= G_MAXUINT16) port_value = g_ascii_strtoll (val, &end, 10);
if (end && *end == '\0' && port_value > 0 && port_value <= G_MAXUINT16)
{ {
*port = (guint16) port_value; *port = (guint16) port_value;
*has_port = TRUE; *has_port = TRUE;
@@ -371,7 +373,12 @@ sts_parse_value (const char *value, guint16 *port, guint64 *duration, gboolean *
continue; continue;
} }
duration_value = g_ascii_strtoull (val, NULL, 10); end = NULL;
duration_value = g_ascii_strtoull (val, &end, 10);
if (!end || *end != '\0')
{
continue;
}
*duration = duration_value; *duration = duration_value;
*has_duration = TRUE; *has_duration = TRUE;
} }
@@ -612,7 +619,7 @@ sts_handle_capability (struct server *serv, const char *value)
{ {
time_t now = time (NULL); time_t now = time (NULL);
time_t expires_at = now + (time_t) duration; time_t expires_at = now + (time_t) duration;
guint16 effective_port = 0; guint16 effective_port = (guint16) serv->port;
sts_profile *existing_profile; sts_profile *existing_profile;
sts_profile *profile; sts_profile *profile;