From 67bcbf5256137eb167ea7483a3a7700a5707aaa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Wed, 1 Nov 2023 14:17:15 +0100 Subject: [PATCH] core, plugins: set error to NULL before calling strtol() This is not strictly necessary, just in case the function strtol() doesn't update the pointer. --- src/core/hook/wee-hook-process.c | 1 + src/core/wee-command.c | 3 +++ src/core/wee-config-file.c | 1 + src/core/wee-eval.c | 11 +++++++++++ src/core/wee-string.c | 1 + src/gui/gui-buffer.c | 4 ++++ src/gui/gui-chat.c | 1 + src/plugins/buflist/buflist-mouse.c | 3 +++ src/plugins/irc/irc-list.c | 4 ++++ src/plugins/irc/irc-message.c | 2 ++ src/plugins/irc/irc-protocol.c | 1 + src/plugins/irc/irc-redirect.c | 4 ++++ src/plugins/plugin-api-info.c | 2 ++ src/plugins/relay/relay-auth.c | 1 + src/plugins/xfer/xfer-network.c | 1 + 15 files changed, 40 insertions(+) diff --git a/src/core/hook/wee-hook-process.c b/src/core/hook/wee-hook-process.c index ccfb5f47d..4240f9b4e 100644 --- a/src/core/hook/wee-hook-process.c +++ b/src/core/hook/wee-hook-process.c @@ -146,6 +146,7 @@ hook_process_hashtable (struct t_weechat_plugin *plugin, ptr_value = hashtable_get (options, "buffer_flush"); if (ptr_value && ptr_value[0]) { + error = NULL; number = strtol (ptr_value, &error, 10); if (error && !error[0] && (number >= 1) && (number <= HOOK_PROCESS_BUFFER_SIZE)) diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 7520570a7..8c1fcb105 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -739,6 +739,7 @@ COMMAND_CALLBACK(buffer) else { ptr_buffer = gui_buffer_search_by_number_or_name (argv[i]); + error = NULL; (void) strtol (argv[i], &error, 10); clear_number = (error && !error[0]); } @@ -974,6 +975,7 @@ COMMAND_CALLBACK(buffer) ptr_buffer = gui_buffer_search_by_number_or_name (argv[i]); if (ptr_buffer) { + error = NULL; (void) strtol (argv[i], &error, 10); if (error && !error[0]) { @@ -1012,6 +1014,7 @@ COMMAND_CALLBACK(buffer) ptr_buffer = gui_buffer_search_by_number_or_name (argv[i]); if (ptr_buffer) { + error = NULL; (void) strtol (argv[i], &error, 10); if (error && !error[0]) { diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c index 59551fff2..c3619d839 100644 --- a/src/core/wee-config-file.c +++ b/src/core/wee-config-file.c @@ -3258,6 +3258,7 @@ config_file_parse_version (const char *version) if (!version) return -1; + error = NULL; number = strtoll (version, &error, 10); if (!error || error[0]) return -1; diff --git a/src/core/wee-eval.c b/src/core/wee-eval.c index b5afac0de..c2370b504 100644 --- a/src/core/wee-eval.c +++ b/src/core/wee-eval.c @@ -413,6 +413,7 @@ eval_string_cut (const char *text, int screen) if (!tmp) return strdup (""); + error = NULL; number = strtol (tmp, &error, 10); if (!error || error[0] || (number < 0)) { @@ -453,6 +454,7 @@ eval_string_repeat (const char *text) if (!tmp) return strdup (""); + error = NULL; number = strtol (tmp, &error, 10); if (!error || error[0] || (number < 0)) { @@ -538,6 +540,7 @@ eval_string_split (const char *text) } else { + error = NULL; number = strtol (str_number, &error, 10); if (!error || error[0] || (number == 0)) goto end; @@ -578,6 +581,7 @@ eval_string_split (const char *text) } else if (strncmp (list_flags[i], "max_items=", 10) == 0) { + error = NULL; max_items = strtol (list_flags[i] + 10, &error, 10); if (!error || error[0] || (max_items < 0)) goto end; @@ -686,6 +690,7 @@ eval_string_split_shell (const char *text) } else { + error = NULL; number = strtol (str_number, &error, 10); if (!error || error[0] || (number == 0)) goto end; @@ -766,6 +771,7 @@ eval_string_regex_group (const char *text, struct t_eval_context *eval_context) } else { + error = NULL; number = strtol (text, &error, 10); if (!error || error[0]) number = -1; @@ -897,6 +903,7 @@ eval_string_base_encode (const char *text) if (!base) goto end; + error = NULL; number = strtol (base, &error, 10); if (!error || error[0]) goto end; @@ -946,6 +953,7 @@ eval_string_base_decode (const char *text) if (!base) goto end; + error = NULL; number = strtol (base, &error, 10); if (!error || error[0]) goto end; @@ -1087,6 +1095,7 @@ eval_string_random (const char *text) tmp = string_strndup (text, pos - text); if (!tmp) goto error; + error = NULL; min_number = strtoll (tmp, &error, 10); if (!error || error[0]) { @@ -1095,6 +1104,7 @@ eval_string_random (const char *text) } free (tmp); + error = NULL; max_number = strtoll (pos + 1, &error, 10); if (!error || error[0]) goto error; @@ -2616,6 +2626,7 @@ eval_expression (const char *expr, struct t_hashtable *pointers, ptr_value = hashtable_get (options, "debug"); if (ptr_value && ptr_value[0]) { + error = NULL; number = strtol (ptr_value, &error, 10); if (error && !error[0] && (number >= 1)) { diff --git a/src/core/wee-string.c b/src/core/wee-string.c index ab0bee82e..986fe2dfe 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -3343,6 +3343,7 @@ string_parse_size (const char *size) if (!str_number) goto end; + error = NULL; number = strtoll (str_number, &error, 10); if (!error || error[0]) goto end; diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index 114902a52..f89b553f2 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -2213,6 +2213,7 @@ gui_buffer_set_unread (struct t_gui_buffer *buffer, const char *argument) else if (argument[0] == '-') { /* move the unread marker N lines towards the first line */ + error = NULL; number = strtol (argument, &error, 10); if (error && !error[0] && (number < 0)) { @@ -2240,6 +2241,7 @@ gui_buffer_set_unread (struct t_gui_buffer *buffer, const char *argument) else if (argument[0] == '+') { /* move the unread marker N lines towards the last line */ + error = NULL; number = strtol (argument, &error, 10); if (error && !error[0] && (number > 0)) { @@ -2265,6 +2267,7 @@ gui_buffer_set_unread (struct t_gui_buffer *buffer, const char *argument) else { /* move the unread marker N lines from the end towards the first line */ + error = NULL; number = strtol (argument, &error, 10); if (error && !error[0] && (number > 0)) { @@ -2953,6 +2956,7 @@ gui_buffer_search_by_number_or_name (const char *string) ptr_buffer = NULL; + error = NULL; number = strtol (string, &error, 10); if (error && !error[0]) { diff --git a/src/gui/gui-chat.c b/src/gui/gui-chat.c index b4471d59c..5c4e1a085 100644 --- a/src/gui/gui-chat.c +++ b/src/gui/gui-chat.c @@ -1079,6 +1079,7 @@ gui_chat_hsignal_quote_line_cb (const void *pointer, void *data, hashtable_get (hashtable, "_chat_line_date") : NULL; if (date) { + error = NULL; number = strtol (date, &error, 10); if (error && !error[0]) { diff --git a/src/plugins/buflist/buflist-mouse.c b/src/plugins/buflist/buflist-mouse.c index d8ade4e80..352e0bd85 100644 --- a/src/plugins/buflist/buflist-mouse.c +++ b/src/plugins/buflist/buflist-mouse.c @@ -62,6 +62,7 @@ buflist_focus_cb (const void *pointer, void *data, struct t_hashtable *info) ptr_bar_item_line = weechat_hashtable_get (info, "_bar_item_line"); if (!ptr_bar_item_line) goto end; + error = NULL; item_line = strtol (ptr_bar_item_line, &error, 10); if (!error || error[0]) goto end; @@ -250,9 +251,11 @@ buflist_hsignal_cb (const void *pointer, void *data, const char *signal, return WEECHAT_RC_OK; ptr_buffer = (struct t_gui_buffer *)value; + error = NULL; number = strtol (ptr_number, &error, 10); if (!error || error[0]) return WEECHAT_RC_OK; + error = NULL; number2 = strtol (ptr_number2, &error, 10); if (!error || error[0]) return WEECHAT_RC_OK; diff --git a/src/plugins/irc/irc-list.c b/src/plugins/irc/irc-list.c index c4c41ddd2..2d509753c 100644 --- a/src/plugins/irc/irc-list.c +++ b/src/plugins/irc/irc-list.c @@ -281,6 +281,7 @@ irc_list_channel_match_filter (struct t_irc_server *server, else if (strncmp (server->list->filter, "u:>", 3) == 0) { /* filter by users (> N)*/ + error = NULL; number = strtol (server->list->filter + 3, &error, 10); if (error && !error[0] && channel->users > (int)number) return 1; @@ -288,6 +289,7 @@ irc_list_channel_match_filter (struct t_irc_server *server, else if (strncmp (server->list->filter, "u:<", 3) == 0) { /* filter by users (< N)*/ + error = NULL; number = strtol (server->list->filter + 3, &error, 10); if (error && !error[0] && channel->users < (int)number) return 1; @@ -295,6 +297,7 @@ irc_list_channel_match_filter (struct t_irc_server *server, else if (strncmp (server->list->filter, "u:", 2) == 0) { /* filter by users */ + error = NULL; number = strtol (server->list->filter + 2, &error, 10); if (error && !error[0] && channel->users >= (int)number) return 1; @@ -437,6 +440,7 @@ irc_list_parse_messages (struct t_irc_server *server, const char *output) ptr_name++; } channel->name2 = strdup (ptr_name); + error = NULL; number = strtol (params[2], &error, 10); channel->users = (error && !error[0]) ? number : 0; channel->topic = (num_params > 3) ? diff --git a/src/plugins/irc/irc-message.c b/src/plugins/irc/irc-message.c index 4889dc7a1..e85d7b14a 100644 --- a/src/plugins/irc/irc-message.c +++ b/src/plugins/irc/irc-message.c @@ -625,6 +625,7 @@ irc_message_parse_cap_multiline_value (struct t_irc_server *server, ptr_value = (const char *)weechat_hashtable_get (values, "max-bytes"); if (ptr_value) { + error = NULL; number = strtol (ptr_value, &error, 10); if (error && !error[0]) server->multiline_max_bytes = number; @@ -633,6 +634,7 @@ irc_message_parse_cap_multiline_value (struct t_irc_server *server, ptr_value = (const char *)weechat_hashtable_get (values, "max-lines"); if (ptr_value) { + error = NULL; number = strtol (ptr_value, &error, 10); if (error && !error[0]) server->multiline_max_lines = number; diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index e9bdc3653..6a7415c3d 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -341,6 +341,7 @@ irc_protocol_parse_time (const char *time) pos = strchr (time2, ','); if (pos) pos[0] = '\0'; + error = NULL; value = strtol (time2, &error, 10); if (error && !error[0] && (value >= 0)) time_value = (int)value; diff --git a/src/plugins/irc/irc-redirect.c b/src/plugins/irc/irc-redirect.c index 7102b4819..71aff5cec 100644 --- a/src/plugins/irc/irc-redirect.c +++ b/src/plugins/irc/irc-redirect.c @@ -462,6 +462,7 @@ irc_redirect_new_with_commands (struct t_irc_server *server, if (pos) { pos[0] = '\0'; + error = NULL; value = strtol (pos + 1, &error, 10); if (!error || error[0]) value = -1; @@ -1309,6 +1310,7 @@ irc_redirect_pattern_hsignal_cb (const void *pointer, void *data, timeout = 0; if (str_timeout && str_timeout[0]) { + error = NULL; number = (int)strtol (str_timeout, &error, 10); if (error && !error[0]) timeout = number; @@ -1379,6 +1381,7 @@ irc_redirect_command_hsignal_cb (const void *pointer, void *data, count = 1; if (str_count && str_count[0]) { + error = NULL; number = (int)strtol (str_count, &error, 10); if (error && !error[0]) count = number; @@ -1387,6 +1390,7 @@ irc_redirect_command_hsignal_cb (const void *pointer, void *data, timeout = 0; if (str_timeout && str_timeout[0]) { + error = NULL; number = (int)strtol (str_timeout, &error, 10); if (error && !error[0]) timeout = number; diff --git a/src/plugins/plugin-api-info.c b/src/plugins/plugin-api-info.c index 4d9f07b42..8dc586e2d 100644 --- a/src/plugins/plugin-api-info.c +++ b/src/plugins/plugin-api-info.c @@ -877,6 +877,7 @@ plugin_api_info_nick_color_ignore_case_cb (const void *pointer, void *data, case_range = -1; if (num_items >= 2) { + error = NULL; number = strtol (items[1], &error, 10); if (error && !error[0]) case_range = (int)number; @@ -916,6 +917,7 @@ plugin_api_info_nick_color_name_ignore_case_cb (const void *pointer, void *data, case_range = -1; if (num_items >= 2) { + error = NULL; number = strtol (items[1], &error, 10); if (error && !error[0]) case_range = (int)number; diff --git a/src/plugins/relay/relay-auth.c b/src/plugins/relay/relay-auth.c index 57ace728c..110412413 100644 --- a/src/plugins/relay/relay-auth.c +++ b/src/plugins/relay/relay-auth.c @@ -247,6 +247,7 @@ relay_auth_parse_pbkdf2 (const char *parameters, } /* parameter 2: iterations */ + error = NULL; *iterations = (int)strtol (argv[1], &error, 10); if (!error || error[0]) *iterations = 0; diff --git a/src/plugins/xfer/xfer-network.c b/src/plugins/xfer/xfer-network.c index 3c7b63338..9639c22d8 100644 --- a/src/plugins/xfer/xfer-network.c +++ b/src/plugins/xfer/xfer-network.c @@ -63,6 +63,7 @@ xfer_network_convert_integer_to_ipv4 (const char *str_address) if (!str_address || !str_address[0]) return NULL; + error = NULL; number = strtoll (str_address, &error, 10); if (!error || error[0] || (number <= 0) || (number > UINT32_MAX)) return NULL;