Skip to content

Commit

Permalink
Don't require message-tags to check for message-tags
Browse files Browse the repository at this point in the history
Found by: DasBrain, Lord255
Patch by: Geo
Fixes: #1179

One-line summary:
Don't require message-tags to check for message-tags

account-tag, server-time and batch can all use message-tags without the message-tags capability actually being enabled. The previous implementation incorrectly assumed any capability requiring message-tags would... well, would require message-tags to be enabled. If this case presented, Eggdrop would then enter a bad state. This corrects the implementation to always check for message-tags present in a message, rather than only if message-tags is enabled.
  • Loading branch information
vanosg committed Oct 22, 2021
1 parent 1fb5875 commit 6d44d1a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 47 deletions.
3 changes: 1 addition & 2 deletions src/mod/server.mod/server.c
Expand Up @@ -95,7 +95,6 @@ static int kick_method;
static int optimize_kicks;
static int msgrate; /* Number of seconds between sending
* queued lines to server. */
static int msgtag; /* Enable IRCv3 message-tags capability */
#ifdef TLS
static int use_ssl; /* Use SSL for the next server connection? */
static int tls_vfyserver; /* Certificate validation mode for servrs */
Expand Down Expand Up @@ -2189,7 +2188,7 @@ static Function server_table[] = {
/* 12 - 15 */
(Function) match_my_nick,
(Function) check_tcl_flud,
(Function) & msgtag, /* int */
(Function) NULL, /* was msgtag in 1.9.0, 1.9.1 */
(Function) & answer_ctcp, /* int */
/* 16 - 19 */
(Function) & trigger_on_ignore, /* int */
Expand Down
2 changes: 1 addition & 1 deletion src/mod/server.mod/server.h
Expand Up @@ -51,7 +51,7 @@
/* 12 - 15 */
#define match_my_nick ((int(*)(char *))server_funcs[12])
#define check_tcl_flud ((int (*)(char *,char *,struct userrec *,char *,char *))server_funcs[13])
#define msgtag (*(int *)(server_funcs[14]))
/* Empty, formally msgtag */
#define answer_ctcp (*(int *)(server_funcs[15]))
/* 16 - 19 */
#define trigger_on_ignore (*(int *)(server_funcs[16]))
Expand Down
83 changes: 40 additions & 43 deletions src/mod/server.mod/servmsg.c
Expand Up @@ -211,12 +211,11 @@ static int check_tcl_rawt(char *from, char *code, char *msg, char *tagstr)
Tcl_SetVar(interp, "_rawt2", code, 0);
Tcl_SetVar(interp, "_rawt3", msg, 0);
ptr = strtok(tagstr, " ");
if (!msgtag) {
Tcl_SetVar(interp, "_rawt4", NULL, 0);
} else {
while (ptr != NULL) {
Tcl_DStringAppendElement(&tagdict, ptr);
while (ptr != NULL) {
ptr = strtok(NULL, " ");
if (ptr) {
Tcl_DStringAppendElement(&tagdict, ptr);
ptr = strtok(NULL, " ");
}
}
Tcl_SetVar(interp, "_rawt4", Tcl_DStringValue(&tagdict), 0);
Expand Down Expand Up @@ -1148,42 +1147,40 @@ static void server_activity(int idx, char *tagmsg, int len)
/* Check if message-tags are enabled and, if so, check/grab the tag */
msgptr = tagmsg;
strlcpy(rawmsg, tagmsg, TOTALTAGMAX+1);
if (msgtag) {
if (*tagmsg == '@') {
taglen = 0;
tagstrptr = newsplit(&msgptr);
strlcpy(tagstr, tagstrptr, TOTALTAGMAX+1);
tagstrptr++; /* Remove @ */
/* Split each key/value pair apart, then split the key from the value */
for (i = 0, s1 = tagstrptr; ; i++, s1 = NULL){
token = strtok_r(s1, ";", &saveptr1);
if (token == NULL) {
break;
}
if (*token == '+') {
token++;
}
if (strchr(token, '=')) {
found = 0;
for (s2 = token; ; s2 = NULL) {
subtoken = strtok_r(s2, "=", &saveptr2);
if (subtoken == NULL) {
break;
}
taglen += egg_snprintf(tagdict + taglen, TOTALTAGMAX - taglen,
"%s ", subtoken);
found++;
}
/* Account for tags (not key/value pairs), prep empty value for Tcl */
if (found < 2) {
taglen += egg_snprintf(tagdict + taglen, TOTALTAGMAX - taglen,
"{} ");
if (*tagmsg == '@') {
taglen = 0;
tagstrptr = newsplit(&msgptr);
strlcpy(tagstr, tagstrptr, TOTALTAGMAX+1);
tagstrptr++; /* Remove @ */
/* Split each key/value pair apart, then split the key from the value */
for (i = 0, s1 = tagstrptr; ; i++, s1 = NULL){
token = strtok_r(s1, ";", &saveptr1);
if (token == NULL) {
break;
}
if (*token == '+') {
token++;
}
if (strchr(token, '=')) {
found = 0;
for (s2 = token; ; s2 = NULL) {
subtoken = strtok_r(s2, "=", &saveptr2);
if (subtoken == NULL) {
break;
}
taglen += egg_snprintf(tagdict + taglen, TOTALTAGMAX - taglen,
"%s ", subtoken);
found++;
}
/* Account for tags (not key/value pairs), prep empty value for Tcl */
if (found < 2) {
taglen += egg_snprintf(tagdict + taglen, TOTALTAGMAX - taglen,
"{} ");
}
}
if (taglen > 0) {
tagdict[taglen-1] = '\0'; /* Remove trailing space */
}
}
if (taglen > 0) {
tagdict[taglen-1] = '\0'; /* Remove trailing space */
}
}
from = "";
Expand Down Expand Up @@ -1655,7 +1652,7 @@ struct capability *find_capability(char *capname) {
struct capability *current = cap;

while (current != NULL) {
if (!strcmp(capname, current->name)) {
if (!strcasecmp(capname, current->name)) {
return current;
}
current = current->next;
Expand Down Expand Up @@ -1899,16 +1896,16 @@ static int gotcap(char *from, char *msg) {
remove = 1;
splitstr++;
}
if (!strcmp(splitstr, current->name)) {
if (!strcasecmp(splitstr, current->name)) {
if (remove) {
current->enabled = 0;
} else {
current->enabled = 1;
}

if ((sasl) && (!strcmp(current->name, "sasl")) && (current->enabled)) {
if ((sasl) && (!strcasecmp(current->name, "sasl")) && (current->enabled)) {
putlog(LOG_DEBUG, "*", "SASL: Starting authentication process");
if (!checkvalue(current->value, SASL_MECHANISMS[sasl_mechanism])) {
if (current->value && !checkvalue(current->value, SASL_MECHANISMS[sasl_mechanism])) {
snprintf(buf, sizeof buf,
"%s authentication method not supported",
SASL_MECHANISMS[sasl_mechanism]);
Expand Down Expand Up @@ -1942,7 +1939,7 @@ static int gotcap(char *from, char *msg) {
}
current = find_capability("sasl");
/* Let SASL code send END if SASL is enabled, to avoid race condition */
if (!current->enabled) {
if (!current || !current->enabled) {
dprintf(DP_MODE, "CAP END\n");
}
current = cap;
Expand Down
4 changes: 3 additions & 1 deletion src/mod/server.mod/tclserv.c
Expand Up @@ -226,11 +226,13 @@ static int tcl_tagmsg STDVAR {
char tag[CLITAGMAX-9]; /* minus @, TAGMSG and two spaces */
char tagdict[CLITAGMAX-9];
char target[MSGMAX];
struct capability *current = 0;
char *p;
int taglen = 0, i = 1;
BADARGS(3, 3, " tag target");

if (!msgtag) {
current = find_capability("message-tags");
if ((!current) || (!(current->enabled))) {
Tcl_AppendResult(irp, "message-tags not enabled, cannot send tag", NULL);
return TCL_ERROR;
}
Expand Down

0 comments on commit 6d44d1a

Please sign in to comment.