Skip to content

Commit 45e8fdd

Browse files
author
Adam Hockley
committed
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.
1 parent 48d4fde commit 45e8fdd

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

modules/m_rehash.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,14 @@ rehash_motd(struct Client *source_p)
103103
{
104104
struct stat sb;
105105
struct tm *local_tm;
106-
char motd_path[PATH_MAX];
107106

108107
sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
109108
"%s is forcing re-reading of MOTD file",
110109
get_oper_name(source_p));
111110
if (!MyConnect(source_p))
112111
remote_rehash_oper_p = source_p;
113112

114-
free_cachefile(user_motd);
115-
user_motd = cache_file(MPATH, "ircd.motd", 0);
116-
117-
/* Construct the full file path for stat() */
118-
rb_snprintf(motd_path, sizeof(motd_path), "%s/ircd.motd", MPATH);
119-
120-
/* Get the file's modification time (not the directory's) */
121-
if(stat(motd_path, &sb) == 0) {
113+
if(stat(MPATH, &sb) == 0) {
122114
local_tm = localtime(&sb.st_mtime);
123115

124116
if(local_tm != NULL) {
@@ -129,6 +121,8 @@ rehash_motd(struct Client *source_p)
129121
local_tm->tm_min);
130122
}
131123
}
124+
free_cachefile(user_motd);
125+
user_motd = cache_file(MPATH, "ircd.motd", 0);
132126
}
133127

134128
static void

0 commit comments

Comments
 (0)