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
This commit is contained in:
scorpion-26 2023-08-22 15:14:13 +02:00
parent 1a25dbdec6
commit ec478dec9c

View file

@ -234,10 +234,27 @@ namespace SNI
{ {
GVariant* tooltipVar; GVariant* tooltipVar;
g_variant_get_child(tooltip, 0, "v", &tooltipVar); g_variant_get_child(tooltip, 0, "v", &tooltipVar);
const gchar* title; const gchar* title = nullptr;
// Both telegram and discord only set the "title" component if (g_variant_is_container(tooltipVar) && g_variant_n_children(tooltipVar) >= 4)
g_variant_get_child(tooltipVar, 2, "s", &title); {
item.tooltip = title; // 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); LOG("SNI: Title: " << item.tooltip);
g_variant_unref(tooltip); g_variant_unref(tooltip);
g_variant_unref(tooltipVar); g_variant_unref(tooltipVar);