From 4420447e7470b224c6de29b5947a55eaa54a95d8 Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Mon, 19 Feb 2024 01:50:40 -0800 Subject: [PATCH] fix(bar): use std::string for mode names `string_view` leads to UAF when reading custom mode definitions from the configuration. --- include/bar.hpp | 8 ++++---- src/bar.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/bar.hpp b/include/bar.hpp index 0cacc3d7..e218496c 100644 --- a/include/bar.hpp +++ b/include/bar.hpp @@ -71,16 +71,16 @@ class BarSurface { class Bar { public: - using bar_mode_map = std::map; + using bar_mode_map = std::map; static const bar_mode_map PRESET_MODES; - static const std::string_view MODE_DEFAULT; - static const std::string_view MODE_INVISIBLE; + static const std::string MODE_DEFAULT; + static const std::string MODE_INVISIBLE; Bar(struct waybar_output *w_output, const Json::Value &); Bar(const Bar &) = delete; ~Bar(); - void setMode(const std::string_view &); + void setMode(const std::string &mode); void setVisible(bool visible); void toggle(); void handleSignal(int); diff --git a/src/bar.cpp b/src/bar.cpp index e919ded2..f7847ae1 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -54,8 +54,8 @@ const Bar::bar_mode_map Bar::PRESET_MODES = { // .passthrough = true, .visible = true}}}; -const std::string_view Bar::MODE_DEFAULT = "default"; -const std::string_view Bar::MODE_INVISIBLE = "invisible"; +const std::string Bar::MODE_DEFAULT = "default"; +const std::string Bar::MODE_INVISIBLE = "invisible"; const std::string_view DEFAULT_BAR_ID = "bar-0"; /* Deserializer for enum bar_layer */ @@ -117,7 +117,7 @@ Glib::ustring to_string(Gtk::PositionType pos) { * Assumes that all the values in the object are deserializable to the same type. */ template ::value>> + typename = std::enable_if_t::value>> void from_json(const Json::Value& j, std::map& m) { if (j.isObject()) { for (auto it = j.begin(); it != j.end(); ++it) { @@ -409,7 +409,7 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config) /* Need to define it here because of forward declared members */ waybar::Bar::~Bar() = default; -void waybar::Bar::setMode(const std::string_view& mode) { +void waybar::Bar::setMode(const std::string& mode) { using namespace std::literals::string_literals; auto style = window.get_style_context();