From 48d4fde94186e591bf070432a6b15bc0c8a88d7c Mon Sep 17 00:00:00 2001 From: Adam Hockley Date: Mon, 17 Nov 2025 08:12:27 +0000 Subject: [PATCH 1/2] Update m_rehash.c test the rehash now Signed-off-by: Adam Hockley --- modules/m_rehash.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/m_rehash.c b/modules/m_rehash.c index d8730d7e..e6c7c483 100644 --- a/modules/m_rehash.c +++ b/modules/m_rehash.c @@ -44,6 +44,7 @@ #include "hash.h" #include "cache.h" #include "sslproc.h" + static int mo_rehash(struct Client *, struct Client *, int, const char **); static int me_rehash(struct Client *, struct Client *, int, const char **); @@ -102,6 +103,7 @@ rehash_motd(struct Client *source_p) { struct stat sb; struct tm *local_tm; + char motd_path[PATH_MAX]; sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s is forcing re-reading of MOTD file", @@ -112,7 +114,11 @@ rehash_motd(struct Client *source_p) free_cachefile(user_motd); user_motd = cache_file(MPATH, "ircd.motd", 0); - if(stat(MPATH, &sb) == 0) { + /* Construct the full file path for stat() */ + rb_snprintf(motd_path, sizeof(motd_path), "%s/ircd.motd", MPATH); + + /* Get the file's modification time (not the directory's) */ + if(stat(motd_path, &sb) == 0) { local_tm = localtime(&sb.st_mtime); if(local_tm != NULL) { From 45e8fdd63459d3458306f2f74bed42e192114876 Mon Sep 17 00:00:00 2001 From: Adam Hockley Date: Mon, 17 Nov 2025 09:16:22 +0000 Subject: [PATCH 2/2] Fix crash in /rehash motd - correct order of operations Fixed the order to match cache_user_motd() - stat() must be called before free_cachefile() to avoid potential race conditions or crashes. The stat() call should happen first to get file metadata, then free and reload the cache. --- modules/m_rehash.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/modules/m_rehash.c b/modules/m_rehash.c index e6c7c483..75eaacbc 100644 --- a/modules/m_rehash.c +++ b/modules/m_rehash.c @@ -103,7 +103,6 @@ rehash_motd(struct Client *source_p) { struct stat sb; struct tm *local_tm; - char motd_path[PATH_MAX]; sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s is forcing re-reading of MOTD file", @@ -111,14 +110,7 @@ rehash_motd(struct Client *source_p) if (!MyConnect(source_p)) remote_rehash_oper_p = source_p; - free_cachefile(user_motd); - user_motd = cache_file(MPATH, "ircd.motd", 0); - - /* Construct the full file path for stat() */ - rb_snprintf(motd_path, sizeof(motd_path), "%s/ircd.motd", MPATH); - - /* Get the file's modification time (not the directory's) */ - if(stat(motd_path, &sb) == 0) { + if(stat(MPATH, &sb) == 0) { local_tm = localtime(&sb.st_mtime); if(local_tm != NULL) { @@ -129,6 +121,8 @@ rehash_motd(struct Client *source_p) local_tm->tm_min); } } + free_cachefile(user_motd); + user_motd = cache_file(MPATH, "ircd.motd", 0); } static void