From 0bacb31d17ac1068a38db342dbcfef6b6abcd684 Mon Sep 17 00:00:00 2001 From: Mark Thompson <129641948+NotherNgineer@users.noreply.github.com> Date: Sat, 28 Oct 2023 14:32:59 -0500 Subject: [PATCH] Improve blacklist to require precise app name matches (#1532) * Add files via upload * Add files via upload * Add files via upload * Clang * Update ui_btngrid.cpp * Update comment --- firmware/application/ui/ui_btngrid.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/firmware/application/ui/ui_btngrid.cpp b/firmware/application/ui/ui_btngrid.cpp index 666fb1da..101c67ec 100644 --- a/firmware/application/ui/ui_btngrid.cpp +++ b/firmware/application/ui/ui_btngrid.cpp @@ -246,13 +246,24 @@ void load_blacklist() { if (error) return; - blacklist_ptr = std::unique_ptr(new char[f.size()]); - if (f.read(blacklist_ptr.get(), f.size())) - blacklist_len = f.size(); + // allocating two extra bytes for leading & trailing commas + blacklist_ptr = std::unique_ptr(new char[f.size() + 2]); + if (f.read(blacklist_ptr.get() + 1, f.size())) { + blacklist_len = f.size() + 2; + + // replace any CR/LF characters with comma delineator, and add comma prefix/suffix, to simplify searching + char* ptr = blacklist_ptr.get(); + *ptr = ','; + *(ptr + blacklist_len - 1) = ','; + for (size_t i = 0; i < blacklist_len; i++, ptr++) { + if (*ptr == 0x0D || *ptr == 0x0A) + *ptr = ','; + } + } } bool BtnGridView::blacklisted_app(GridItem new_item) { - std::string app_name = new_item.text; + std::string app_name = "," + new_item.text + ","; if (blacklist_len < app_name.size()) return false;