From f53983bc790b8201431ee18fd5411311df6fabd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Wed, 1 Nov 2023 09:09:00 +0100 Subject: [PATCH] core: display an error with command `/history N` when N is not a valid integer --- ChangeLog.adoc | 1 + src/core/wee-command.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 5b08feae6..9c9aae167 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -24,6 +24,7 @@ New features:: Bug fixes:: + * core: display an error with command `/history N` when N is not a valid integer * core: fix memory leak when config version is invalid or not supported * core: fix crash when "config_version" is present in a configuration file without a value * core: display an error on startup if environment variable "HOME" is not set diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 00631cc6a..f0361db58 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -3386,6 +3386,7 @@ COMMAND_CALLBACK(history) { struct t_gui_history *ptr_history; int n, n_total, n_user, displayed; + char *error; /* make C compiler happy */ (void) pointer; @@ -3402,7 +3403,12 @@ COMMAND_CALLBACK(history) return WEECHAT_RC_OK; } else - n_user = atoi (argv[1]); + { + error = NULL; + n_user = (int)strtol (argv[1], &error, 10); + if (!error || error[0] || (n_user < 0)) + COMMAND_ERROR; + } } if (buffer->history)