From 94afbe9c8e423280d28e4ab296d868c8a42c0bc6 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 21 Jun 2016 17:32:28 -0700 Subject: [PATCH 1/2] ircd: Fix capability entry name string ownership. The entry->cap must be copied and exclusive to the entry for the cap to be orphaned, even if literals are expected. Because modules. --- ircd/capability.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ircd/capability.c b/ircd/capability.c index 618c127a..f82821d9 100644 --- a/ircd/capability.c +++ b/ircd/capability.c @@ -71,7 +71,7 @@ capability_put(struct CapabilityIndex *idx, const char *cap, void *ownerdata) } entry = rb_malloc(sizeof(struct CapabilityEntry)); - entry->cap = cap; + entry->cap = rb_strdup(cap); entry->flags = 0; entry->value = idx->highest_bit; entry->ownerdata = ownerdata; @@ -133,7 +133,9 @@ capability_destroy(rb_dictionary_element *delem, void *privdata) { s_assert(delem != NULL); - rb_free(delem->data); + struct CapabilityEntry *entry = delem->data; + rb_free((char *)entry->cap); + rb_free(entry); } struct CapabilityIndex * From b5cfad03195d566cd259154d212875fb238f5d80 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 21 Jun 2016 17:39:44 -0700 Subject: [PATCH 2/2] Core modules cannot be unloaded, otherwise bad things happen. Additionally some information is logged and passed to the operator conducting a MODRESTART. --- ircd/modules.c | 3 +++ modules/core/m_modules.c | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ircd/modules.c b/ircd/modules.c index 839eb012..1d969af7 100644 --- a/ircd/modules.c +++ b/ircd/modules.c @@ -294,6 +294,9 @@ unload_one_module(const char *name, bool warn) if((mod = findmodule_byname(name)) == NULL) return false; + if(mod->core) + return false; + /* ** XXX - The type system in C does not allow direct conversion between ** data and function pointers, but as it happens, most C compilers will diff --git a/modules/core/m_modules.c b/modules/core/m_modules.c index 7eee253b..813a444b 100644 --- a/modules/core/m_modules.c +++ b/modules/core/m_modules.c @@ -349,7 +349,19 @@ do_modrestart(struct Client *source_p) RB_DLINK_FOREACH_SAFE(ptr, nptr, module_list.head) { struct module *mod = ptr->data; - unload_one_module(mod->name, false); + if(!unload_one_module(mod->name, false)) + { + ilog(L_MAIN, "Module Restart: %s was not unloaded %s", + mod->name, + mod->core? "(core module)" : ""); + + if(!mod->core) + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, + "Module Restart: %s failed to unload", + mod->name); + continue; + } + modnum++; }