filter: fix part handling

previously we would have formatted a null pointer into %s for the
command, which is theoretically bad but handled by glibc
This commit is contained in:
Ed Kellett 2020-05-02 02:52:21 +01:00
parent c7561f03ef
commit e9408bc4fc
No known key found for this signature in database
GPG key ID: CB9986DEF342FABC

View file

@ -70,6 +70,7 @@ static int filter_enable = 1;
static const char *cmdname[MESSAGE_TYPE_COUNT] = { static const char *cmdname[MESSAGE_TYPE_COUNT] = {
[MESSAGE_TYPE_PRIVMSG] = "PRIVMSG", [MESSAGE_TYPE_PRIVMSG] = "PRIVMSG",
[MESSAGE_TYPE_NOTICE] = "NOTICE", [MESSAGE_TYPE_NOTICE] = "NOTICE",
[MESSAGE_TYPE_PART] = "PART",
}; };
enum filter_state { enum filter_state {
@ -343,6 +344,8 @@ unsigned match_message(const char *prefix,
return 0; return 0;
if (!filter_db) if (!filter_db)
return 0; return 0;
if (!command)
return 0;
snprintf(check_buffer, sizeof check_buffer, "%s:%s!%s@%s#%c %s %s :%s", snprintf(check_buffer, sizeof check_buffer, "%s:%s!%s@%s#%c %s %s :%s",
prefix, prefix,
#if FILTER_NICK #if FILTER_NICK
@ -361,8 +364,7 @@ unsigned match_message(const char *prefix,
"*", "*",
#endif #endif
source->user && source->user->suser[0] != '\0' ? '1' : '0', source->user && source->user->suser[0] != '\0' ? '1' : '0',
command, target, command, target, msg);
msg);
hs_error_t r = hs_scan(filter_db, check_buffer, strlen(check_buffer), 0, filter_scratch, match_callback, &state); hs_error_t r = hs_scan(filter_db, check_buffer, strlen(check_buffer), 0, filter_scratch, match_callback, &state);
if (r != HS_SUCCESS && r != HS_SCAN_TERMINATED) if (r != HS_SUCCESS && r != HS_SCAN_TERMINATED)
return 0; return 0;
@ -464,4 +466,3 @@ on_client_exit(void *data_)
state = filter_db ? FILTER_LOADED : FILTER_EMPTY; state = filter_db ? FILTER_LOADED : FILTER_EMPTY;
} }
} }