]> granicus.if.org Git - p11-kit/commitdiff
modules: check gl.modules before iterates on it when freeing
authorStefano Garzarella <sgarzare@redhat.com>
Wed, 27 Feb 2019 11:25:20 +0000 (12:25 +0100)
committerDaiki Ueno <ueno@gnu.org>
Wed, 27 Feb 2019 13:39:57 +0000 (14:39 +0100)
In some circumstances, as described in the BZ, can happen that
free_modules_when_no_refs_unlocked() is called multiple times
when the module destructor is invoked.
We should check gl.modules before iterates on it in the
free_modules_when_no_refs_unlocked() functions, to avoid
a SIGSEGV.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1680963

p11-kit/modules.c

index 0299edab815190c36382a3d1cc80df005dcd4ae9..891ce4c5270f7a17df9626422a592e9f78b4fa7d 100644 (file)
@@ -797,14 +797,16 @@ init_globals_unlocked (void)
 static void
 free_modules_when_no_refs_unlocked (void)
 {
-       Module *mod;
-       p11_dictiter iter;
-
-       /* Check if any modules have a ref count */
-       p11_dict_iterate (gl.modules, &iter);
-       while (p11_dict_next (&iter, (void **)&mod, NULL)) {
-               if (mod->ref_count)
-                       return;
+       if (gl.modules) {
+               Module *mod;
+               p11_dictiter iter;
+
+               /* Check if any modules have a ref count */
+               p11_dict_iterate (gl.modules, &iter);
+               while (p11_dict_next (&iter, (void **)&mod, NULL)) {
+                       if (mod->ref_count)
+                               return;
+               }
        }
 
        p11_dict_free (gl.unmanaged_by_funcs);