fix segv in address completion with a keyring
authorWerner Koch <wk@gnupg.org>
Sun, 13 Sep 2020 12:07:04 +0000 (14:07 +0200)
committerPaul <paul@claws-mail.org>
Sun, 13 Sep 2020 12:59:16 +0000 (13:59 +0100)
With my keyring and when entering for example "wk@g", then hitting
Tab, b_ref->name is NULL and addr_comparison_func segfaults.  I have
not looked closer at the problem but implemented a straightforward for
for such cases which makes the function more robust in any case.

The bug was probably triggered by my long expired key
A4D94E92B0986AB5EE9DCD755DE249965B0358A2 which has several user ids
with my name and different mail addresses - one user id has no mail
address though.

src/addr_compl.c

index e0e93733afa428497e41ecd6f5a4fe5db8b009e8..ba7cef6d2c64a5d2c44de7cbdcd5796480b12620 100644 (file)
@@ -232,8 +232,18 @@ static gint addr_comparison_func(gconstpointer a, gconstpointer b)
        else if (a_weight > b_weight)
                return 1;
        else {
-               cmp = strcmp(a_ref->name, b_ref->name);
-               return cmp ? cmp : g_strcmp0(a_ref->address, b_ref->address);
+                if (!a_ref->name || !b_ref->name)
+                  cmp = !!a_ref->name - !!b_ref->name;
+                else
+                  cmp = strcmp(a_ref->name, b_ref->name);
+                if (!cmp)
+                  {
+                    if (!a_ref->address || !b_ref->address)
+                      cmp = !!a_ref->address - !!b_ref->address;
+                    else
+                      cmp = g_strcmp0(a_ref->address, b_ref->address);
+                  }
+                return cmp;
        }
 }