diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2023-01-27 20:47:24 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2023-01-28 15:14:22 +0100 |
commit | c07cf691adb4740759e9fd128a2f6702c912d70f (patch) | |
tree | 91520d9be1270aae41d23ffeae1f69d3a31b10d2 /src/plugins | |
parent | c9ac4fef4b7aa054df72bddf667edea0608d39c6 (diff) | |
download | weechat-c07cf691adb4740759e9fd128a2f6702c912d70f.zip |
core, plugins: check that string parameters are not NULL in search functions (issue #1872)
Diffstat (limited to 'src/plugins')
33 files changed, 97 insertions, 32 deletions
diff --git a/src/plugins/alias/alias.c b/src/plugins/alias/alias.c index 587feaeac..824555cde 100644 --- a/src/plugins/alias/alias.c +++ b/src/plugins/alias/alias.c @@ -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) { diff --git a/src/plugins/exec/exec-command.c b/src/plugins/exec/exec-command.c index 7cfec192a..8dc0aa25d 100644 --- a/src/plugins/exec/exec-command.c +++ b/src/plugins/exec/exec-command.c @@ -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) { diff --git a/src/plugins/exec/exec.c b/src/plugins/exec/exec.c index 71447a76b..2928883ef 100644 --- a/src/plugins/exec/exec.c +++ b/src/plugins/exec/exec.c @@ -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]) diff --git a/src/plugins/fset/fset-option.c b/src/plugins/fset/fset-option.c index 748bce747..e6d9c0e86 100644 --- a/src/plugins/fset/fset-option.c +++ b/src/plugins/fset/fset-option.c @@ -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++) { diff --git a/src/plugins/guile/weechat-guile-api.c b/src/plugins/guile/weechat-guile-api.c index c90f6377f..d5678e41e 100644 --- a/src/plugins/guile/weechat-guile-api.c +++ b/src/plugins/guile/weechat-guile-api.c @@ -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, diff --git a/src/plugins/guile/weechat-guile.c b/src/plugins/guile/weechat-guile.c index 40c8bb3e5..d851e09ee 100644 --- a/src/plugins/guile/weechat-guile.c +++ b/src/plugins/guile/weechat-guile.c @@ -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); diff --git a/src/plugins/irc/irc-channel.c b/src/plugins/irc/irc-channel.c index b1aafe41c..3c86cb0fb 100644 --- a/src/plugins/irc/irc-channel.c +++ b/src/plugins/irc/irc-channel.c @@ -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); diff --git a/src/plugins/irc/irc-ignore.c b/src/plugins/irc/irc-ignore.c index b39e107b8..02202e995 100644 --- a/src/plugins/irc/irc-ignore.c +++ b/src/plugins/irc/irc-ignore.c @@ -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) diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index f1f969acb..1c5726bc6 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -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) diff --git a/src/plugins/javascript/weechat-js-api.cpp b/src/plugins/javascript/weechat-js-api.cpp index 5c446ed66..e05419048 100644 --- a/src/plugins/javascript/weechat-js-api.cpp +++ b/src/plugins/javascript/weechat-js-api.cpp @@ -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, diff --git a/src/plugins/javascript/weechat-js.cpp b/src/plugins/javascript/weechat-js.cpp index 7c079af8f..75821b5cc 100644 --- a/src/plugins/javascript/weechat-js.cpp +++ b/src/plugins/javascript/weechat-js.cpp @@ -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); diff --git a/src/plugins/lua/weechat-lua-api.c b/src/plugins/lua/weechat-lua-api.c index 0f5e1a6b8..69ef607e5 100644 --- a/src/plugins/lua/weechat-lua-api.c +++ b/src/plugins/lua/weechat-lua-api.c @@ -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, diff --git a/src/plugins/lua/weechat-lua.c b/src/plugins/lua/weechat-lua.c index 95076fa3f..f42d0b70e 100644 --- a/src/plugins/lua/weechat-lua.c +++ b/src/plugins/lua/weechat-lua.c @@ -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); diff --git a/src/plugins/perl/weechat-perl-api.c b/src/plugins/perl/weechat-perl-api.c index b06d20953..b8b0dac13 100644 --- a/src/plugins/perl/weechat-perl-api.c +++ b/src/plugins/perl/weechat-perl-api.c @@ -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, diff --git a/src/plugins/perl/weechat-perl.c b/src/plugins/perl/weechat-perl.c index 74375e347..bfad79d61 100644 --- a/src/plugins/perl/weechat-perl.c +++ b/src/plugins/perl/weechat-perl.c @@ -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); diff --git a/src/plugins/php/weechat-php-api.c b/src/plugins/php/weechat-php-api.c index 9e10984f5..112af9709 100644 --- a/src/plugins/php/weechat-php-api.c +++ b/src/plugins/php/weechat-php-api.c @@ -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, diff --git a/src/plugins/php/weechat-php.c b/src/plugins/php/weechat-php.c index 928e0e268..ac2cbc508 100644 --- a/src/plugins/php/weechat-php.c +++ b/src/plugins/php/weechat-php.c @@ -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); diff --git a/src/plugins/plugin-config.c b/src/plugins/plugin-config.c index 890bc20ed..df2c2cbf5 100644 --- a/src/plugins/plugin-config.c +++ b/src/plugins/plugin-config.c @@ -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; diff --git a/src/plugins/plugin-script.c b/src/plugins/plugin-script.c index 4a0abe078..533483d03 100644 --- a/src/plugins/plugin-script.c +++ b/src/plugins/plugin-script.c @@ -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 ( diff --git a/src/plugins/plugin-script.h b/src/plugins/plugin-script.h index 9133b3c43..d54751299 100644 --- a/src/plugins/plugin-script.h +++ b/src/plugins/plugin-script.h @@ -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); diff --git a/src/plugins/python/weechat-python-api.c b/src/plugins/python/weechat-python-api.c index 9e50dc006..a54c024e6 100644 --- a/src/plugins/python/weechat-python-api.c +++ b/src/plugins/python/weechat-python-api.c @@ -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, diff --git a/src/plugins/python/weechat-python.c b/src/plugins/python/weechat-python.c index a60209227..94a7d9e95 100644 --- a/src/plugins/python/weechat-python.c +++ b/src/plugins/python/weechat-python.c @@ -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); diff --git a/src/plugins/relay/irc/relay-irc.c b/src/plugins/relay/irc/relay-irc.c index 25c8f6dc1..bd8be06ae 100644 --- a/src/plugins/relay/irc/relay-irc.c +++ b/src/plugins/relay/irc/relay-irc.c @@ -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) diff --git a/src/plugins/relay/relay-client.c b/src/plugins/relay/relay-client.c index 16dd268ff..4e93726e2 100644 --- a/src/plugins/relay/relay-client.c +++ b/src/plugins/relay/relay-client.c @@ -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) diff --git a/src/plugins/relay/relay-server.c b/src/plugins/relay/relay-server.c index a52eaf74b..e00e3bbaf 100644 --- a/src/plugins/relay/relay-server.c +++ b/src/plugins/relay/relay-server.c @@ -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) { diff --git a/src/plugins/relay/relay.c b/src/plugins/relay/relay.c index dd8932ae0..429bc5a54 100644 --- a/src/plugins/relay/relay.c +++ b/src/plugins/relay/relay.c @@ -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) diff --git a/src/plugins/relay/weechat/relay-weechat.c b/src/plugins/relay/weechat/relay-weechat.c index de9ff6535..eea6c5394 100644 --- a/src/plugins/relay/weechat/relay-weechat.c +++ b/src/plugins/relay/weechat/relay-weechat.c @@ -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) diff --git a/src/plugins/ruby/weechat-ruby-api.c b/src/plugins/ruby/weechat-ruby-api.c index 54c894eab..fccec5063 100644 --- a/src/plugins/ruby/weechat-ruby-api.c +++ b/src/plugins/ruby/weechat-ruby-api.c @@ -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, diff --git a/src/plugins/ruby/weechat-ruby.c b/src/plugins/ruby/weechat-ruby.c index ab2645c36..1ce7da62b 100644 --- a/src/plugins/ruby/weechat-ruby.c +++ b/src/plugins/ruby/weechat-ruby.c @@ -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); diff --git a/src/plugins/script/script-repo.c b/src/plugins/script/script-repo.c index df947e098..43376a9fa 100644 --- a/src/plugins/script/script-repo.c +++ b/src/plugins/script/script-repo.c @@ -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) { diff --git a/src/plugins/script/script.c b/src/plugins/script/script.c index 16481c0d4..553ac3765 100644 --- a/src/plugins/script/script.c +++ b/src/plugins/script/script.c @@ -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) diff --git a/src/plugins/tcl/weechat-tcl-api.c b/src/plugins/tcl/weechat-tcl-api.c index 323f8bdf8..c73cf2caa 100644 --- a/src/plugins/tcl/weechat-tcl-api.c +++ b/src/plugins/tcl/weechat-tcl-api.c @@ -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, diff --git a/src/plugins/tcl/weechat-tcl.c b/src/plugins/tcl/weechat-tcl.c index 57d95539e..79d0a5243 100644 --- a/src/plugins/tcl/weechat-tcl.c +++ b/src/plugins/tcl/weechat-tcl.c @@ -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); |