1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-09 03:03:12 +02:00

core, plugins: check that string parameters are not NULL in search functions (issue #1872)

This commit is contained in:
Sébastien Helleu
2023-01-27 20:47:24 +01:00
parent c9ac4fef4b
commit c07cf691ad
40 changed files with 127 additions and 33 deletions
+3
View File
@@ -61,6 +61,9 @@ hook_command_search (struct t_weechat_plugin *plugin, const char *command)
{
struct t_hook *ptr_hook;
if (!command)
return NULL;
for (ptr_hook = weechat_hooks[HOOK_TYPE_COMMAND]; ptr_hook;
ptr_hook = ptr_hook->next_hook)
{
+3
View File
@@ -123,6 +123,9 @@ gui_color_search (const char *color_name)
{
int i;
if (!color_name)
return -1;
for (i = 0; gui_weechat_colors[i].string; i++)
{
if (string_strcmp (gui_weechat_colors[i].string, color_name) == 0)
+5
View File
@@ -2794,11 +2794,16 @@ gui_buffer_search_by_number_or_name (const char *string)
long number;
char *error;
if (!string)
return NULL;
ptr_buffer = NULL;
number = strtol (string, &error, 10);
if (error && !error[0])
{
ptr_buffer = gui_buffer_search_by_number (number);
}
else
{
ptr_buffer = gui_buffer_search_by_full_name (string);
+3
View File
@@ -319,6 +319,9 @@ gui_completion_search_command (struct t_weechat_plugin *plugin,
struct t_hook *ptr_hook, *hook_for_other_plugin, *hook_incomplete_command;
int length_command, allow_incomplete_commands, count_incomplete_commands;
if (!command)
return NULL;
hook_for_other_plugin = NULL;
hook_incomplete_command = NULL;
length_command = utf8_strlen (command);
+6
View File
@@ -710,6 +710,9 @@ gui_key_search (struct t_gui_key *keys, const char *key)
{
struct t_gui_key *ptr_key;
if (!key)
return NULL;
for (ptr_key = keys; ptr_key; ptr_key = ptr_key->next_key)
{
if (strcmp (ptr_key->key, key) == 0)
@@ -756,6 +759,9 @@ gui_key_search_part (struct t_gui_buffer *buffer, int context,
{
struct t_gui_key *ptr_key;
if (!key)
return NULL;
for (ptr_key = (buffer) ? buffer->keys : gui_keys[context]; ptr_key;
ptr_key = ptr_key->next_key)
{
+3
View File
@@ -55,6 +55,9 @@ gui_layout_search (const char *name)
{
struct t_gui_layout *ptr_layout;
if (!name)
return NULL;
for (ptr_layout = gui_layouts; ptr_layout;
ptr_layout = ptr_layout->next_layout)
{
+7 -1
View File
@@ -196,7 +196,7 @@ gui_nicklist_search_group_internal (struct t_gui_buffer *buffer,
struct t_gui_nick_group *ptr_group;
const char *ptr_name;
if (!buffer)
if (!buffer || !name)
return NULL;
if (!from_group)
@@ -242,6 +242,9 @@ gui_nicklist_search_group (struct t_gui_buffer *buffer,
{
const char *ptr_name;
if (!buffer || !name)
return NULL;
ptr_name = gui_nicklist_get_group_start (name);
return gui_nicklist_search_group_internal (buffer, from_group, name,
@@ -388,6 +391,9 @@ gui_nicklist_search_nick (struct t_gui_buffer *buffer,
if (!buffer && !from_group)
return NULL;
if (!name)
return NULL;
if (!from_group && !buffer->nicklist_root)
return NULL;
+3
View File
@@ -84,6 +84,9 @@ alias_search (const char *alias_name)
{
struct t_alias *ptr_alias;
if (!alias_name)
return NULL;
for (ptr_alias = alias_list; ptr_alias;
ptr_alias = ptr_alias->next_alias)
{
+3
View File
@@ -148,6 +148,9 @@ exec_command_search_running_id (const char *id)
{
struct t_exec_cmd *ptr_exec_cmd;
if (!id)
return NULL;
ptr_exec_cmd = exec_search_by_id (id);
if (!ptr_exec_cmd)
{
+3
View File
@@ -86,6 +86,9 @@ exec_search_by_id (const char *id)
char *error;
long number;
if (!id)
return NULL;
error = NULL;
number = strtol (id, &error, 10);
if (!error || error[0])
+3
View File
@@ -102,6 +102,9 @@ fset_option_search_by_name (const char *name, int *line)
if (line)
*line = -1;
if (!name)
return NULL;
num_options = weechat_arraylist_size (fset_options);
for (i = 0; i < num_options; i++)
{
+1 -2
View File
@@ -176,8 +176,7 @@ weechat_guile_api_register (SCM name, SCM author, SCM version, SCM license,
|| !scm_is_string (charset))
API_WRONG_ARGS(API_RETURN_ERROR);
if (plugin_script_search (weechat_guile_plugin, guile_scripts,
API_SCM_TO_STRING(name)))
if (plugin_script_search (guile_scripts, API_SCM_TO_STRING(name)))
{
/* another script already exists with same name */
weechat_printf (NULL,
+2 -2
View File
@@ -668,7 +668,7 @@ weechat_guile_unload_name (const char *name)
{
struct t_plugin_script *ptr_script;
ptr_script = plugin_script_search (weechat_guile_plugin, guile_scripts, name);
ptr_script = plugin_script_search (guile_scripts, name);
if (ptr_script)
{
weechat_guile_unload (ptr_script);
@@ -710,7 +710,7 @@ weechat_guile_reload_name (const char *name)
struct t_plugin_script *ptr_script;
char *filename;
ptr_script = plugin_script_search (weechat_guile_plugin, guile_scripts, name);
ptr_script = plugin_script_search (guile_scripts, name);
if (ptr_script)
{
filename = strdup (ptr_script->filename);
+6
View File
@@ -195,6 +195,9 @@ irc_channel_search_buffer (struct t_irc_server *server, int channel_type,
struct t_gui_buffer *ptr_buffer;
const char *ptr_type, *ptr_server_name, *ptr_channel_name;
if (!channel_name)
return NULL;
hdata_buffer = weechat_hdata_get ("buffer");
ptr_buffer = weechat_hdata_get_list (hdata_buffer, "gui_buffers");
@@ -989,6 +992,9 @@ irc_channel_nick_speaking_time_search (struct t_irc_server *server,
struct t_irc_channel_speaking *ptr_nick;
time_t time_limit;
if (!server || !channel || !nick_name)
return NULL;
time_limit = time (NULL) -
(weechat_config_integer (irc_config_look_smart_filter_delay) * 60);
+3
View File
@@ -73,6 +73,9 @@ irc_ignore_search (const char *mask, const char *server, const char *channel)
struct t_irc_ignore *ptr_ignore;
char any[2] = "*";
if (!mask)
return NULL;
if (!server)
server = any;
if (!channel)
+6
View File
@@ -238,6 +238,9 @@ irc_server_search_casemapping (const char *casemapping)
{
int i;
if (!casemapping)
return -1;
for (i = 0; i < IRC_SERVER_NUM_CASEMAPPING; i++)
{
if (weechat_strcasecmp (irc_server_casemapping_string[i], casemapping) == 0)
@@ -260,6 +263,9 @@ irc_server_search_utf8mapping (const char *utf8mapping)
{
int i;
if (!utf8mapping)
return -1;
for (i = 0; i < IRC_SERVER_NUM_UTF8MAPPING; i++)
{
if (weechat_strcasecmp (irc_server_utf8mapping_string[i], utf8mapping) == 0)
+1 -1
View File
@@ -149,7 +149,7 @@ API_FUNC(register)
v8::String::Utf8Value shutdown_func(args[5]);
v8::String::Utf8Value charset(args[6]);
if (plugin_script_search (weechat_js_plugin, js_scripts, *name))
if (plugin_script_search (js_scripts, *name))
{
/* another script already exists with same name */
weechat_printf (NULL,
+2 -2
View File
@@ -486,7 +486,7 @@ weechat_js_unload_name (const char *name)
{
struct t_plugin_script *ptr_script;
ptr_script = plugin_script_search (weechat_js_plugin, js_scripts, name);
ptr_script = plugin_script_search (js_scripts, name);
if (ptr_script)
{
weechat_js_unload (ptr_script);
@@ -528,7 +528,7 @@ weechat_js_reload_name (const char *name)
struct t_plugin_script *ptr_script;
char *filename;
ptr_script = plugin_script_search (weechat_js_plugin, js_scripts, name);
ptr_script = plugin_script_search (js_scripts, name);
if (ptr_script)
{
filename = strdup (ptr_script->filename);
+1 -1
View File
@@ -154,7 +154,7 @@ API_FUNC(register)
shutdown_func = lua_tostring (L, -2);
charset = lua_tostring (L, -1);
if (plugin_script_search (weechat_lua_plugin, lua_scripts, name))
if (plugin_script_search (lua_scripts, name))
{
/* another script already exists with same name */
weechat_printf (NULL,
+2 -2
View File
@@ -767,7 +767,7 @@ weechat_lua_unload_name (const char *name)
{
struct t_plugin_script *ptr_script;
ptr_script = plugin_script_search (weechat_lua_plugin, lua_scripts, name);
ptr_script = plugin_script_search (lua_scripts, name);
if (ptr_script)
{
weechat_lua_unload (ptr_script);
@@ -796,7 +796,7 @@ weechat_lua_reload_name (const char *name)
struct t_plugin_script *ptr_script;
char *filename;
ptr_script = plugin_script_search (weechat_lua_plugin, lua_scripts, name);
ptr_script = plugin_script_search (lua_scripts, name);
if (ptr_script)
{
filename = strdup (ptr_script->filename);
+1 -1
View File
@@ -133,7 +133,7 @@ API_FUNC(register)
shutdown_func = SvPV_nolen (ST (5));
charset = SvPV_nolen (ST (6));
if (plugin_script_search (weechat_perl_plugin, perl_scripts, name))
if (plugin_script_search (perl_scripts, name))
{
/* another script already exists with same name */
weechat_printf (NULL,
+2 -2
View File
@@ -750,7 +750,7 @@ weechat_perl_unload_name (const char *name)
{
struct t_plugin_script *ptr_script;
ptr_script = plugin_script_search (weechat_perl_plugin, perl_scripts, name);
ptr_script = plugin_script_search (perl_scripts, name);
if (ptr_script)
{
weechat_perl_unload (ptr_script);
@@ -792,7 +792,7 @@ weechat_perl_reload_name (const char *name)
struct t_plugin_script *ptr_script;
char *filename;
ptr_script = plugin_script_search (weechat_perl_plugin, perl_scripts, name);
ptr_script = plugin_script_search (perl_scripts, name);
if (ptr_script)
{
filename = strdup (ptr_script->filename);
+1 -1
View File
@@ -128,7 +128,7 @@ API_FUNC(register)
php_current_script = NULL;
php_registered_script = NULL;
if (plugin_script_search (weechat_php_plugin, php_scripts, ZSTR_VAL(name)))
if (plugin_script_search (php_scripts, ZSTR_VAL(name)))
{
/* another script already exists with same name */
weechat_printf (NULL,
+2 -2
View File
@@ -805,7 +805,7 @@ weechat_php_unload_name (const char *name)
{
struct t_plugin_script *ptr_script;
ptr_script = plugin_script_search (weechat_php_plugin, php_scripts, name);
ptr_script = plugin_script_search (php_scripts, name);
if (ptr_script)
{
weechat_php_unload (ptr_script);
@@ -847,7 +847,7 @@ weechat_php_reload_name (const char *name)
struct t_plugin_script *ptr_script;
char *filename;
ptr_script = plugin_script_search (weechat_php_plugin, php_scripts, name);
ptr_script = plugin_script_search (php_scripts, name);
if (ptr_script)
{
filename = strdup (ptr_script->filename);
+3
View File
@@ -55,6 +55,9 @@ plugin_config_search (const char *plugin_name, const char *option_name)
char *option_full_name;
struct t_config_option *ptr_option;
if (!plugin_name || !option_name)
return NULL;
ptr_option = NULL;
length = strlen (plugin_name) + 1 + strlen (option_name) + 1;
+9 -5
View File
@@ -481,14 +481,13 @@ plugin_script_auto_load (struct t_weechat_plugin *weechat_plugin,
}
/*
* Searches for a script by registered name (example: "iset").
* Searches for a script by registered name.
*
* Returns pointer to script, NULL if not found.
*/
struct t_plugin_script *
plugin_script_search (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *scripts, const char *name)
plugin_script_search (struct t_plugin_script *scripts, const char *name)
{
struct t_plugin_script *ptr_script;
@@ -519,6 +518,9 @@ plugin_script_search_by_full_name (struct t_plugin_script *scripts,
char *base_name;
struct t_plugin_script *ptr_script;
if (!full_name)
return NULL;
for (ptr_script = scripts; ptr_script;
ptr_script = ptr_script->next_script)
{
@@ -545,6 +547,9 @@ plugin_script_search_path (struct t_weechat_plugin *weechat_plugin,
int length;
struct stat st;
if (!filename)
return NULL;
if (filename[0] == '~')
return weechat_string_expand_home (filename);
@@ -820,8 +825,7 @@ plugin_script_set_buffer_callbacks (struct t_weechat_plugin *weechat_plugin,
script_name = weechat_buffer_get_string (ptr_buffer, "localvar_script_name");
if (script_name && script_name[0])
{
ptr_script = plugin_script_search (weechat_plugin, scripts,
script_name);
ptr_script = plugin_script_search (scripts, script_name);
if (ptr_script && (ptr_script == script))
{
str_script_input_cb = weechat_buffer_get_string (
+1 -2
View File
@@ -133,8 +133,7 @@ extern void plugin_script_get_function_and_data (void *callback_data,
extern void plugin_script_auto_load (struct t_weechat_plugin *weechat_plugin,
void (*callback)(void *data,
const char *filename));
extern struct t_plugin_script *plugin_script_search (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *scripts,
extern struct t_plugin_script *plugin_script_search (struct t_plugin_script *scripts,
const char *name);
extern char *plugin_script_search_path (struct t_weechat_plugin *weechat_plugin,
const char *filename);
+1 -1
View File
@@ -115,7 +115,7 @@ API_FUNC(register)
&license, &description, &shutdown_func, &charset))
API_WRONG_ARGS(API_RETURN_ERROR);
if (plugin_script_search (weechat_python_plugin, python_scripts, name))
if (plugin_script_search (python_scripts, name))
{
/* another script already exists with same name */
weechat_printf (NULL,
+2 -2
View File
@@ -993,7 +993,7 @@ weechat_python_unload_name (const char *name)
{
struct t_plugin_script *ptr_script;
ptr_script = plugin_script_search (weechat_python_plugin, python_scripts, name);
ptr_script = plugin_script_search (python_scripts, name);
if (ptr_script)
{
weechat_python_unload (ptr_script);
@@ -1035,7 +1035,7 @@ weechat_python_reload_name (const char *name)
struct t_plugin_script *ptr_script;
char *filename;
ptr_script = plugin_script_search (weechat_python_plugin, python_scripts, name);
ptr_script = plugin_script_search (python_scripts, name);
if (ptr_script)
{
filename = strdup (ptr_script->filename);
+6
View File
@@ -109,6 +109,9 @@ relay_irc_search_backlog_commands_tags (const char *tag)
{
int i;
if (!tag)
return -1;
for (i = 0; i < RELAY_IRC_NUM_CMD; i++)
{
if (strcmp (relay_irc_backlog_commands_tags[i], tag) == 0)
@@ -131,6 +134,9 @@ relay_irc_search_server_capability (const char *capability)
{
int i;
if (!capability)
return -1;
for (i = 0; i < RELAY_IRC_NUM_CAPAB; i++)
{
if (strcmp (relay_irc_server_capabilities[i], capability) == 0)
+3
View File
@@ -150,6 +150,9 @@ relay_client_status_search (const char *name)
{
int i;
if (!name)
return -1;
for (i = 0; i < RELAY_NUM_STATUS; i++)
{
if (strcmp (relay_client_status_name[i], name) == 0)
+6
View File
@@ -170,6 +170,9 @@ relay_server_search (const char *protocol_and_args)
{
struct t_relay_server *ptr_server;
if (!protocol_and_args)
return NULL;
for (ptr_server = relay_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
@@ -213,6 +216,9 @@ relay_server_search_path (const char *path)
{
struct t_relay_server *ptr_server;
if (!path)
return NULL;
for (ptr_server = relay_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
+3
View File
@@ -66,6 +66,9 @@ relay_protocol_search (const char *name)
{
int i;
if (!name)
return -1;
for (i = 0; i < RELAY_NUM_PROTOCOLS; i++)
{
if (strcmp (relay_protocol_string[i], name) == 0)
@@ -56,6 +56,9 @@ relay_weechat_compression_search (const char *compression)
{
int i;
if (!compression)
return -1;
for (i = 0; i < RELAY_WEECHAT_NUM_COMPRESSIONS; i++)
{
if (weechat_strcasecmp (relay_weechat_compression_string[i], compression) == 0)
+1 -1
View File
@@ -125,7 +125,7 @@ weechat_ruby_api_register (VALUE class, VALUE name, VALUE author,
c_shutdown_func = StringValuePtr (shutdown_func);
c_charset = StringValuePtr (charset);
if (plugin_script_search (weechat_ruby_plugin, ruby_scripts, c_name))
if (plugin_script_search (ruby_scripts, c_name))
{
/* another script already exists with same name */
weechat_printf (NULL,
+2 -2
View File
@@ -803,7 +803,7 @@ weechat_ruby_unload_name (const char *name)
{
struct t_plugin_script *ptr_script;
ptr_script = plugin_script_search (weechat_ruby_plugin, ruby_scripts, name);
ptr_script = plugin_script_search (ruby_scripts, name);
if (ptr_script)
{
weechat_ruby_unload (ptr_script);
@@ -832,7 +832,7 @@ weechat_ruby_reload_name (const char *name)
struct t_plugin_script *ptr_script;
char *filename;
ptr_script = plugin_script_search (weechat_ruby_plugin, ruby_scripts, name);
ptr_script = plugin_script_search (ruby_scripts, name);
if (ptr_script)
{
filename = strdup (ptr_script->filename);
+6
View File
@@ -122,6 +122,9 @@ script_repo_search_by_name (const char *name)
{
struct t_script_repo *ptr_script;
if (!name)
return NULL;
for (ptr_script = scripts_repo; ptr_script;
ptr_script = ptr_script->next_script)
{
@@ -144,6 +147,9 @@ script_repo_search_by_name_ext (const char *name_with_extension)
{
struct t_script_repo *ptr_script;
if (!name_with_extension)
return NULL;
for (ptr_script = scripts_repo; ptr_script;
ptr_script = ptr_script->next_script)
{
+6
View File
@@ -67,6 +67,9 @@ script_language_search (const char *language)
{
int i;
if (!language)
return -1;
for (i = 0; i < SCRIPT_NUM_LANGUAGES; i++)
{
if (strcmp (script_language[i], language) == 0)
@@ -88,6 +91,9 @@ script_language_search_by_extension (const char *extension)
{
int i;
if (!extension)
return -1;
for (i = 0; i < SCRIPT_NUM_LANGUAGES; i++)
{
if (strcmp (script_extension[i], extension) == 0)
+1 -1
View File
@@ -254,7 +254,7 @@ API_FUNC(register)
shutdown_func = Tcl_GetStringFromObj (objv[6], &i);
charset = Tcl_GetStringFromObj (objv[7], &i);
if (plugin_script_search (weechat_tcl_plugin, tcl_scripts, name))
if (plugin_script_search (tcl_scripts, name))
{
/* another script already exists with same name */
weechat_printf (NULL,
+2 -2
View File
@@ -487,7 +487,7 @@ weechat_tcl_unload_name (const char *name)
{
struct t_plugin_script *ptr_script;
ptr_script = plugin_script_search (weechat_tcl_plugin, tcl_scripts, name);
ptr_script = plugin_script_search (tcl_scripts, name);
if (ptr_script)
{
weechat_tcl_unload (ptr_script);
@@ -529,7 +529,7 @@ weechat_tcl_reload_name (const char *name)
struct t_plugin_script *ptr_script;
char *filename;
ptr_script = plugin_script_search (weechat_tcl_plugin, tcl_scripts, name);
ptr_script = plugin_script_search (tcl_scripts, name);
if (ptr_script)
{
filename = strdup (ptr_script->filename);