From bd36b5e310650e019c2794fb852e50180fffec2c Mon Sep 17 00:00:00 2001 From: jcorporation Date: Thu, 12 Dec 2024 19:39:17 +0100 Subject: [PATCH] Response with error for sticker set,inc,dec and add missing asserts --- src/command/StickerCommands.cxx | 22 +++++++++++++++++++--- src/sticker/Database.cxx | 5 ++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/command/StickerCommands.cxx b/src/command/StickerCommands.cxx index 1e21bb885b..6eccc653f9 100644 --- a/src/command/StickerCommands.cxx +++ b/src/command/StickerCommands.cxx @@ -17,6 +17,7 @@ #include "Instance.hxx" #include "util/StringAPI.hxx" #include "util/ScopeExit.hxx" +#include "util/StringCompare.hxx" #include "tag/Settings.hxx" #include "tag/ParseName.hxx" #include "tag/Names.hxx" @@ -456,16 +457,31 @@ handle_sticker(Client &client, Request args, Response &r) return handler->List(uri); /* set */ - if (args.size() == 5 && StringIsEqual(cmd, "set")) + if (args.size() == 5 && StringIsEqual(cmd, "set")) { + if (StringIsEmpty(sticker_name)) { + r.FmtError(ACK_ERROR_ARG, "empty sticker name"); + return CommandResult::ERROR; + } return handler->Set(uri, sticker_name, args[4]); + } /* inc */ - if (args.size() == 5 && StringIsEqual(cmd, "inc")) + if (args.size() == 5 && StringIsEqual(cmd, "inc")) { + if (StringIsEmpty(sticker_name)) { + r.FmtError(ACK_ERROR_ARG, "empty sticker name"); + return CommandResult::ERROR; + } return handler->Inc(uri, sticker_name, args[4]); + } /* dec */ - if (args.size() == 5 && StringIsEqual(cmd, "dec")) + if (args.size() == 5 && StringIsEqual(cmd, "dec")) { + if (StringIsEmpty(sticker_name)) { + r.FmtError(ACK_ERROR_ARG, "empty sticker name"); + return CommandResult::ERROR; + } return handler->Dec(uri, sticker_name, args[4]); + } /* delete */ if ((args.size() == 3 || args.size() == 4) && StringIsEqual(cmd, "delete")) diff --git a/src/sticker/Database.cxx b/src/sticker/Database.cxx index 95dcad221f..88d84988bb 100644 --- a/src/sticker/Database.cxx +++ b/src/sticker/Database.cxx @@ -283,11 +283,9 @@ StickerDatabase::StoreValue(const char *type, const char *uri, assert(type != nullptr); assert(uri != nullptr); assert(name != nullptr); + assert(*name != 0); assert(value != nullptr); - if (StringIsEmpty(name)) - return; - if (!UpdateValue(type, uri, name, value)) InsertValue(type, uri, name, value); } @@ -367,6 +365,7 @@ StickerDatabase::DeleteValue(const char *type, const char *uri, assert(type != nullptr); assert(uri != nullptr); + assert(name != nullptr); BindAll(s, type, uri, name);