Skip to content

Commit aaca079

Browse files
author
Adam Hockley
committed
Fix NULL pointer dereference in load_help() function
- Add NULL check before irc_dictionary_add() calls - Prevents crash when cache_file() returns NULL (file errors, empty files, memory allocation failures) - Fixes potential crash in help file loading
1 parent 9e4adea commit aaca079

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/cache.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ load_help(void)
266266
continue;
267267
rb_snprintf(filename, sizeof(filename), "%s/%s", HPATH, ldirent->d_name);
268268
cacheptr = cache_file(filename, ldirent->d_name, HELP_OPER);
269-
irc_dictionary_add(help_dict_oper, cacheptr->name, cacheptr);
269+
if(cacheptr != NULL)
270+
irc_dictionary_add(help_dict_oper, cacheptr->name, cacheptr);
270271
}
271272

272273
closedir(helpfile_dir);
@@ -298,7 +299,8 @@ load_help(void)
298299
#endif
299300

300301
cacheptr = cache_file(filename, ldirent->d_name, HELP_USER);
301-
irc_dictionary_add(help_dict_user, cacheptr->name, cacheptr);
302+
if(cacheptr != NULL)
303+
irc_dictionary_add(help_dict_user, cacheptr->name, cacheptr);
302304
}
303305

304306
closedir(helpfile_dir);

0 commit comments

Comments
 (0)