From 7fabd8068f11505de6348b0ee9b271d06b04817e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Wed, 1 Nov 2023 14:22:32 +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-message.c | 2 ++ src/plugins/irc/irc-protocol.c | 1 + src/plugins/irc/irc-redirect.c | 4 ++++ src/plugins/relay/relay-auth.c | 1 + src/plugins/xfer/xfer-network.c | 1 + 13 files changed, 34 insertions(+) diff --git a/src/core/hook/wee-hook-process.c b/src/core/hook/wee-hook-process.c index a779f0144..0762e4e19 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 6f5869866..23b2f54bd 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -736,6 +736,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]); } @@ -971,6 +972,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]) { @@ -1009,6 +1011,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 f11dd36b2..db1c967a2 100644 --- a/src/core/wee-config-file.c +++ b/src/core/wee-config-file.c @@ -3158,6 +3158,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 b828a972d..7c4d8cd10 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; @@ -2618,6 +2628,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 83ee9e63c..27b7ad009 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -3279,6 +3279,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 88a0248ff..1d7522d2b 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -2145,6 +2145,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)) { @@ -2172,6 +2173,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)) { @@ -2197,6 +2199,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)) { @@ -2885,6 +2888,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-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 dd687d7f6..f1222aee8 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/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 5ba39b4bf..ee6ec7620 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;