From 0938f431b34b020b09991f830f3387e95197a13a Mon Sep 17 00:00:00 2001 From: moreveal Date: Tue, 27 Aug 2024 01:50:24 +0300 Subject: [PATCH] Fix #970: Correct validation of TABLIST_HEADERS dialogs --- Server/Components/Dialogs/dialog.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Server/Components/Dialogs/dialog.cpp b/Server/Components/Dialogs/dialog.cpp index da3fc9b10..3cb00e02b 100644 --- a/Server/Components/Dialogs/dialog.cpp +++ b/Server/Components/Dialogs/dialog.cpp @@ -168,21 +168,30 @@ class DialogsComponent final : public IDialogsComponent, public PlayerConnectEve if ((data->style_ == DialogStyle_LIST || data->style_ == DialogStyle_TABLIST || data->style_ == DialogStyle_TABLIST_HEADERS) && data->body_.length() > 0) { unsigned int lines = 0; - - for (unsigned int i = 0; i < data->body_.length() - 1; i++) + + for (unsigned int i = 0; i < data->body_.length(); i++) { - if (data->body_[i] == '\n') + if (data->body_[i] != '\n' && i > 0 && data->body_[i - 1] == '\n') { lines++; } } - if (data->style_ == DialogStyle_TABLIST_HEADERS && lines > 0) + if (data->style_ == DialogStyle_TABLIST_HEADERS) + { + if (lines <= 1) + { + sendDialogResponse.ListItem = 0; + lines = 1; + } + } + else { - lines--; + if (lines == 0) sendDialogResponse.ListItem = 0; + lines++; } - if (sendDialogResponse.ListItem < 0 || sendDialogResponse.ListItem > lines) + if (sendDialogResponse.ListItem < 0 || sendDialogResponse.ListItem >= lines) { return false; }