From ec478dec9c9d3fd019c8593ce679893cb15d4680 Mon Sep 17 00:00:00 2001 From: scorpion-26 Date: Tue, 22 Aug 2023 15:14:13 +0200 Subject: [PATCH] SNI: Fix crash with ToolTip of type String TeamViewer exposes ToolTip as String (which is not compliant to the spec). This caused gBar to crash, since we assume, that the tooltip variant is always a container (struct), which glibc doesn't like. We now fallback to g_variant_get_string if it is not according to spec Fixes https://github.com/scorpion-26/gBar/issues/37 --- src/SNI.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/SNI.cpp b/src/SNI.cpp index 557ed08..689799a 100644 --- a/src/SNI.cpp +++ b/src/SNI.cpp @@ -234,10 +234,27 @@ namespace SNI { GVariant* tooltipVar; g_variant_get_child(tooltip, 0, "v", &tooltipVar); - const gchar* title; - // Both telegram and discord only set the "title" component - g_variant_get_child(tooltipVar, 2, "s", &title); - item.tooltip = title; + const gchar* title = nullptr; + if (g_variant_is_container(tooltipVar) && g_variant_n_children(tooltipVar) >= 4) + { + // According to spec, ToolTip is of type (sa(iiab)ss) => 4 children + // Most icons only set the "title" component (e.g. Discord, KeePassXC, ...) + g_variant_get_child(tooltipVar, 2, "s", &title); + } + else + { + // TeamViewer only exposes a string, which is not according to spec! + title = g_variant_get_string(tooltipVar, nullptr); + } + + if (title != nullptr) + { + item.tooltip = title; + } + else + { + LOG("SNI: Error querying tooltip"); + } LOG("SNI: Title: " << item.tooltip); g_variant_unref(tooltip); g_variant_unref(tooltipVar);