Hello,

I've met an issue with GNSRECORD which is similar to [0] but a bit more
subtle.

As the commit message of the attached patch explains, when GNSRECORD is
used after `GNUNET_OS_init' is called with a non-GNUnet project data,
the necessary plugins are not loaded since the path is different.

Naturally, since the plugins are not loaded, GNSRECORD will always fail
when trying to operate on a record; that's how I discovered this issue:
I was trying to parse a TXT record obtained from GNS, but it kept
failing without a clear explanation. I had to go read the GNSRECORD
source code to understand why I kept getting a NULL value.

Admittedly, I didn't test these changes, however they seems pretty
trivial so unless I misunderstood how the plugin loader works, they
shouldn't cause any problem.

Thanks,
A.V.

[0] https://lists.gnu.org/archive/html/gnunet-developers/2020-07/msg00009.html

>From 998126274cca69b87dd58d04d7b62514d121e496 Mon Sep 17 00:00:00 2001
From: Alessio Vanni <[email protected]>
Date: Wed, 15 Jul 2020 17:21:39 +0200
Subject: [PATCH] Load GNSRECORD plugins within GNUnet's context

When applications set a new project data structure using `GNUNET_OS_init', the
plugin loader will look into a different path for plugins, instead of using
GNUnet's installation path.

Since applications don't normally come with the default DNS/GNS plugins for
GNSRECORD, the consequence is that GNSRECORD will always fail when operating
on a record from GNS.
---
 src/gnsrecord/gnsrecord.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/gnsrecord/gnsrecord.c b/src/gnsrecord/gnsrecord.c
index c6ebd7c29..3ce10473b 100644
--- a/src/gnsrecord/gnsrecord.c
+++ b/src/gnsrecord/gnsrecord.c
@@ -102,8 +102,15 @@ init ()
   if (1 == once)
     return;
   once = 1;
+  struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get ();
+  struct GNUNET_OS_ProjectData *dpd = GNUNET_OS_project_data_default ();
+
+  if (pd != dpd)
+    GNUNET_OS_init(dpd);
   GNUNET_PLUGIN_load_all ("libgnunet_plugin_gnsrecord_", NULL,
                           &add_plugin, NULL);
+  if (pd != dpd)
+    GNUNET_OS_init(pd);
 }
 
 
@@ -114,6 +121,11 @@ void __attribute__ ((destructor))
 GNSRECORD_fini ()
 {
   struct Plugin *plugin;
+  struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get ();
+  struct GNUNET_OS_ProjectData *dpd = GNUNET_OS_project_data_default ();
+
+  if (pd != dpd)
+    GNUNET_OS_init(dpd);
 
   for (unsigned int i = 0; i < num_plugins; i++)
   {
@@ -125,6 +137,10 @@ GNSRECORD_fini ()
     GNUNET_free (plugin);
   }
   GNUNET_free (gns_plugins);
+
+  if (pd != dpd)
+    GNUNET_OS_init(dpd);
+
   gns_plugins = NULL;
   once = 0;
   num_plugins = 0;
-- 
2.26.2

Reply via email to