Fix crash and memory leak in $aliasctl(COMMAND MATCH)

glob_commands() would run off the end of the irc_command array if given a match that matched
the last command.  It also leaked memory because it used m_s3cat() to construct the string,
then passed that to m_strdup().

This fixes these problems by reworking glob_commands(), and at the same time removes the use
of alloca() and wild_match() by using strncmp() instead to match the start of a string.  Move
glob_commands() to alias.c and make it static since it's only used for aliasctl().

Change the 'name' argument of find_command() and find_dll_command() to const char * at the same
time, so that glob_commands()'s prefix argument can be const char * too.
This commit is contained in:
Kevin Easton
2016-10-15 00:41:34 +11:00
parent dec7caafd0
commit 9a2792345f
5 changed files with 32 additions and 28 deletions

View File

@@ -627,7 +627,7 @@ extern Function_ptr *global;
#define io (*(void (*)(const char *))global[IRC_IO_FUNC])
/* commands.c */
#define find_command (*(IrcCommand *(*)(char *, int *))global[FIND_COMMAND_FUNC])
#define find_command (*(IrcCommand *(*)(const char *, int *))global[FIND_COMMAND_FUNC])
#define lock_stack_frame (*(void (*)(void ))global[LOCK_STACK_FRAME])
#define unlock_stack_frame (*(void (*)(void ))global[UNLOCK_STACK_FRAME])