Getting optional channel parameter was buggy - it used already free'd memory

and assumed the command handler was given CHANNEL_REC even while it could
have been any other WI_ITEM_REC ..though it used only the WI_ITEM_REC parts
so it didn't really matter..


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1544 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2001-06-10 22:19:15 +00:00 committed by cras
commit b0f75f79a2

View file

@ -23,6 +23,7 @@
#include "commands.h" #include "commands.h"
#include "misc.h" #include "misc.h"
#include "special-vars.h" #include "special-vars.h"
#include "window-item-def.h"
#include "servers.h" #include "servers.h"
#include "servers-redirect.h" #include "servers-redirect.h"
@ -619,12 +620,12 @@ typedef struct {
GHashTable *options; GHashTable *options;
} CMD_TEMP_REC; } CMD_TEMP_REC;
static char *get_optional_channel(CHANNEL_REC *active_channel, char **data) static char *get_optional_channel(WI_ITEM_REC *active_item, char **data)
{ {
CHANNEL_REC *chanrec; CHANNEL_REC *chanrec;
char *tmp, *origtmp, *channel, *ret; char *tmp, *origtmp, *channel, *ret;
if (active_channel == NULL) { if (active_item == NULL) {
/* no active channel in window, channel required */ /* no active channel in window, channel required */
return cmd_get_param(data); return cmd_get_param(data);
} }
@ -633,14 +634,15 @@ static char *get_optional_channel(CHANNEL_REC *active_channel, char **data)
channel = cmd_get_param(&tmp); channel = cmd_get_param(&tmp);
if (strcmp(channel, "*") == 0 || if (strcmp(channel, "*") == 0 ||
!active_channel->server->ischannel(channel)) !active_item->server->ischannel(channel))
ret = active_channel->name; ret = active_item->name;
else { else {
/* Find the channel first and use it's name if found. /* Find the channel first and use it's name if found.
This allows automatic !channel -> !XXXXXchannel replaces. */ This allows automatic !channel -> !XXXXXchannel replaces. */
chanrec = channel_find(active_channel->server, channel); channel = cmd_get_param(data);
chanrec = channel_find(active_item->server, channel);
ret = chanrec == NULL ? channel : chanrec->name; ret = chanrec == NULL ? channel : chanrec->name;
cmd_get_param(data);
} }
g_free(origtmp); g_free(origtmp);
@ -649,7 +651,7 @@ static char *get_optional_channel(CHANNEL_REC *active_channel, char **data)
int cmd_get_params(const char *data, gpointer *free_me, int count, ...) int cmd_get_params(const char *data, gpointer *free_me, int count, ...)
{ {
CHANNEL_REC *chanrec; WI_ITEM_REC *item;
CMD_TEMP_REC *rec; CMD_TEMP_REC *rec;
GHashTable **opthash; GHashTable **opthash;
char **str, *arg, *datad; char **str, *arg, *datad;
@ -667,8 +669,8 @@ int cmd_get_params(const char *data, gpointer *free_me, int count, ...)
datad = rec->data; datad = rec->data;
error = FALSE; error = FALSE;
chanrec = (count & PARAM_FLAG_OPTCHAN) == 0 ? NULL: item = (count & PARAM_FLAG_OPTCHAN) == 0 ? NULL:
(CHANNEL_REC *) va_arg(args, CHANNEL_REC *); (WI_ITEM_REC *) va_arg(args, WI_ITEM_REC *);
if (count & PARAM_FLAG_OPTIONS) { if (count & PARAM_FLAG_OPTIONS) {
arg = (char *) va_arg(args, char *); arg = (char *) va_arg(args, char *);
@ -688,7 +690,7 @@ int cmd_get_params(const char *data, gpointer *free_me, int count, ...)
cnt = PARAM_WITHOUT_FLAGS(count); cnt = PARAM_WITHOUT_FLAGS(count);
if (count & PARAM_FLAG_OPTCHAN) { if (count & PARAM_FLAG_OPTCHAN) {
/* optional channel as first parameter */ /* optional channel as first parameter */
arg = get_optional_channel(chanrec, &datad); arg = get_optional_channel(item, &datad);
str = (char **) va_arg(args, char **); str = (char **) va_arg(args, char **);
if (str != NULL) *str = arg; if (str != NULL) *str = arg;