tumblerd crashes when no plugins installed: NULL pointer in g_variant_builder_add_value

Steps to Reproduce

  1. Build tumbler without any plugins (empty /usr/lib64/tumbler-1/plugins/)
  2. Boot system and login to XFCE
  3. tumblerd crashes immediately on D-Bus GetSupported call
tumblerd[1138]: segfault at 30 ip 00007fc5dc169fb0 sp 00007ffd03ee3be8 error 4 in libglib-2.0.so.0.8600.3

Enviorment:

tumbler 4.20.1
glib 2.86.3
gdk-pixbuf 2.44.4

Core dump:

#0  g_variant_is_trusted (value=value@entry=0x0) at glib/gvariant-core.c:844
#1  g_variant_builder_add_value (builder=0x7ffc93538b70, value=0x0) at glib/gvariant.c:3605
#2  g_variant_valist_new (str=0x7ffc93538c28, app=0x7ffc93538c50) at glib/gvariant.c:5369
#3  g_variant_new_va (format_string="(^as^as)", ...) at glib/gvariant.c:5545
#4  g_variant_new (format_string="(^as^as)") at glib/gvariant.c:5480
#5  tumbler_exported_service_complete_get_supported (..., uri_schemes=<optimized out>, mime_types=<optimized out>) at tumbler-service-gdbus.c:1901
#6  tumbler_service_get_supported_cb (skeleton=0x562d979e8de0, invocation=0x7f850c003230, service=0x562d979d41c0) at tumbler-service.c:934
        mime_types = 0x0     NULL!
        uri_schemes = 0x0    NULL!

tumblerd/tumbler-registry.c:642-658:

void
tumbler_registry_get_supported (TumblerRegistry *registry,
                                const gchar *const **uri_schemes,
                                const gchar *const **mime_types)
{
  g_return_if_fail (TUMBLER_IS_REGISTRY (registry));

  tumbler_mutex_lock (registry->mutex);

  if (uri_schemes != NULL)
    *uri_schemes = (const gchar *const *) registry->uri_schemes;  // no plugins installed, NULL

  if (mime_types != NULL)
    *mime_types = (const gchar *const *) registry->mime_types;    // no plugins install, NULL

  tumbler_mutex_unlock (registry->mutex);
}

actually, no plugins installed:

root@qemux86-64:~# ls -la /usr/lib64/tumbler-1/plugins/
total 12
drwxr-xr-x 3 root root 4096 Apr  5  2011 .
drwxr-xr-x 4 root root 4096 Apr  5  2011 ..
drwxr-xr-x 3 root root 4096 Apr  5  2011 cache
# No any plugins installed

Root Cause

  • tumbler_registry_get_supported() returns NULL for both uri_schemes and mime_types when no plugins installed
  • tumbler_service_get_supported_cb() passes these NULLs directly to g_variant_new("(^as^as)", ...)
  • GLib's ^as format expects valid string arrays, not NULL
  • Crash in g_variant_builder_add_value() when dereferencing NULL

Should add Null check after tumbler_registry_get_supported() in tumbler_service_get_supported_cb()? to avoid the crashed?

Edited by Peng Zhang