From 33ab2a368dc21935f7c522a37109a8ae8b50be41 Mon Sep 17 00:00:00 2001 From: eleksir Date: Mon, 18 Apr 2022 23:19:19 +0300 Subject: [PATCH] More strict check of redis message json format --- lib/BotLib.pm | 2 +- lib/RedisLib.pm | 8 +++++++- lib/TelegramBot.pm | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/BotLib.pm b/lib/BotLib.pm index b9fcef5..1f035e0 100644 --- a/lib/BotLib.pm +++ b/lib/BotLib.pm @@ -16,7 +16,7 @@ use BotLib::Conf qw (LoadConf); use BotLib::Admin qw (@ForbiddenMessageTypes GetForbiddenTypes AddForbiddenType DelForbiddenType ListForbidden FortuneToggle FortuneStatus PluginToggle PluginStatus PluginEnabled ChanMsgToggle ChanMsgStatus - GreetMsgToggle GreetMsgStatus GoodbyeMsgToggle GoodbyeMsgStatus); + GreetMsgToggle GreetMsgStatus GoodbyeMsgToggle GoodbyeMsgStatus); use BotLib::Util qw (trim); use version; our $VERSION = qw (1.1); diff --git a/lib/RedisLib.pm b/lib/RedisLib.pm index 535468d..6d16bea 100644 --- a/lib/RedisLib.pm +++ b/lib/RedisLib.pm @@ -37,7 +37,13 @@ sub redis_parse_message { $message->{parse_mode} = 'Markdown'; } - $message->{chat_id} = 0 + $m->{chatid}; + $message->{chat_id} = eval { 0 + $m->{chatid}; }; + + unless (defined $message->{chat_id}) { + log->error ('Incoming redis message is incorrect: chat id must be numeric value!'); + return; + } + $message->{text} = "$m->{message}"; my $can_talk = Teapot::Bot::Object::ChatPermissions->canTalk ($main::TGM, 0 + $m->{chatid}); diff --git a/lib/TelegramBot.pm b/lib/TelegramBot.pm index 2a023db..3acd0a1 100644 --- a/lib/TelegramBot.pm +++ b/lib/TelegramBot.pm @@ -71,6 +71,10 @@ sub __cron { if ($hour == 8 && ($min >= 0 && $min <= 14)) { foreach my $enabledfortunechat (FortuneToggleList ()) { # Set it to strings, explicitly + next unless (defined $enabledfortunechat); + next if ("$enabledfortunechat" eq ''); + next if ("$enabledfortunechat" eq '0'); + $rmsg->{userid} = "$enabledfortunechat"; $rmsg->{chatid} = "$enabledfortunechat";