From b46af3de4cb3dc9b4f9eb03a75dfbeb52c20920e Mon Sep 17 00:00:00 2001 From: Rick L Bird Date: Tue, 10 May 2011 07:31:32 -0400 Subject: [PATCH] Fixed crash bug when no arg_right was present --- src/modules.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/modules.c b/src/modules.c index e23634c..4347c3a 100644 --- a/src/modules.c +++ b/src/modules.c @@ -23,6 +23,7 @@ #include "match.h" #include "modules.h" +static int cancel_hooks = 0; struct module_entry_t *module_list = NULL; HASHTAB chook_htab; HASHTAB chook_mevents; /* MUSH Events aliased to Hooks */ @@ -77,8 +78,7 @@ CHooks_Init() hashinit(&chook_mevents, sz); for (sz = i = 0; chook_tab[i].key != NULL; i++) if (chook_tab[i].mush_key != NULL) - hashadd(chook_tab[i].mush_key, (void *) chook_tab[i].key, - &chook_mevents); + hashadd(chook_tab[i].mush_key, (void *) chook_tab[i].key, &chook_mevents); } struct core_hook_t * @@ -205,6 +205,17 @@ COMMAND(cmd_event) char *key; char *s; + if(!arg_left[0] || !arg_right[0]) { + notify(player, "Not gonna cut it."); + return; + } + + /* Look for event */ + if (!(key = (char *) hashfind(arg_left, &chook_mevents))) { + notify(player, "No such event."); + return; + } + s = strchr(arg_right, '/'); *s++ = '\0'; @@ -212,15 +223,11 @@ COMMAND(cmd_event) notify(player, "Bad Event format"); return; } + thing = match_thing(player, arg_right); if (!GoodObject(thing)) return; - /* Look for event */ - if (!(key = (char *) hashfind(arg_left, &chook_mevents))) { - notify(player, "No such event."); - return; - } if (!CHook_Insert_SC(key, thing, s)) { /* This shouldn't happen.. */ @@ -263,6 +270,8 @@ CHook_Run(struct core_entry_t *entry, const char *format, ...) int rval; int (*module_func) (struct core_entry_t * entry, va_list argp); + if (cancel_hooks) + return -1; module_func = NULL; /* Just for initialization purposes */ va_start(argp, format); if (entry->flags & MODHOOK_SOFTCODE) { @@ -352,12 +361,13 @@ CHook_SC(struct core_entry_t *entry, const char *format, va_list arguments) break; default: /* Bad Format.. don't run & return an error */ + cancel_hooks = 1; /* prevent recursions */ do_rawlog(LT_ERR, "%s:%d -> Unexpected format character '%c' in format \"%s\"", __FILE__, __LINE__, *fptr, format); + cancel_hooks = 0; /* Restore Environment */ - copy_namedregs(&global_eval_context.namedregs, - &preserve_namedregs); + copy_namedregs(&global_eval_context.namedregs, &preserve_namedregs); free_namedregs(&preserve_namedregs); restore_global_regs("chook_sc_save", preserveq); restore_global_env("chook_sc_save", preserves); @@ -379,8 +389,7 @@ CHook_SC(struct core_entry_t *entry, const char *format, va_list arguments) local_ooref = ooref; ooref = atr->creator; process_expression(cmd_buf, &r, &s, - executor, enactor, cause, PE_NOTHING, PT_SEMI, - NULL); + executor, enactor, cause, PE_NOTHING, PT_SEMI, NULL); *r = '\0'; if (*s == ';') s++; @@ -492,8 +501,7 @@ module_open(char *path, char *name) handle = lt_dlopen(file); if (!handle) { - do_rawlog(LT_ERR, "Error Loading Module: %s | %s ", file, - lt_dlerror()); + do_rawlog(LT_ERR, "Error Loading Module: %s | %s ", file, lt_dlerror()); return 0; } @@ -502,8 +510,7 @@ module_open(char *path, char *name) if (!module_loader) { do_rawlog(LT_ERR, - "Error Loading Module: Could not call module_load | %s", - file); + "Error Loading Module: Could not call module_load | %s", file); return 0; } @@ -542,8 +549,7 @@ module_close(struct module_entry_t *m) } if (!module_entry_del(m)) { - do_rawlog(LT_ERR, "Could not unload module: %s/%d ", __FILE__, - __LINE__); + do_rawlog(LT_ERR, "Could not unload module: %s/%d ", __FILE__, __LINE__); return 0; } -- 2.30.2