From 62bd4ad64ebf1567c05170353dd7c60813c4f284 Mon Sep 17 00:00:00 2001 From: Alessio Vanni Date: Sat, 30 Oct 2021 16:07:08 +0200 Subject: -fix subtle bug in GNUNET_CONFIGURATION_default Apparently this was there since the beginning and it wasn't caught earlier merely due to a coincidence. Basically, it was looking at the caller's values instead of GNUnet's and even when I used this function in personal projects, it just happened that I was calling this function before setting the new project data, so the two environments ended up being the same. It didn't cause any issues because it was still returning GNUnet's own configuration, meaning everything else worked as expected, but naturally if one were to move the call later on it would break. Also add a comment to answer the FIXME. --- src/util/configuration.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/util') diff --git a/src/util/configuration.c b/src/util/configuration.c index 09a3a7d93..d9d6721cc 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c @@ -2383,31 +2383,34 @@ GNUNET_CONFIGURATION_default (void) char *cfgname = NULL; struct GNUNET_CONFIGURATION_Handle *cfg; - /* FIXME: Why are we doing this? Needs some commentary! */ + /* Makes sure function implicitly looking at the installation directory (for + example GNUNET_CONFIGURATION_load further down) use GNUnet's environment + instead of the caller's. It's done at the start to make sure as many + functions as possible are directed to the proper paths. */ GNUNET_OS_init (dpd); cfg = GNUNET_CONFIGURATION_create (); /* First, try user configuration. */ if (NULL != xdg) - GNUNET_asprintf (&cfgname, "%s/%s", xdg, pd->config_file); + GNUNET_asprintf (&cfgname, "%s/%s", xdg, dpd->config_file); else - cfgname = GNUNET_strdup (pd->user_config_file); + cfgname = GNUNET_strdup (dpd->user_config_file); /* If user config doesn't exist, try in /etc// and /etc/ */ if (GNUNET_OK != GNUNET_DISK_file_test (cfgname)) { GNUNET_free (cfgname); - GNUNET_asprintf (&cfgname, "/etc/%s", pd->config_file); + GNUNET_asprintf (&cfgname, "/etc/%s", dpd->config_file); } if (GNUNET_OK != GNUNET_DISK_file_test (cfgname)) { GNUNET_free (cfgname); GNUNET_asprintf (&cfgname, "/etc/%s/%s", - pd->project_dirname, - pd->config_file); + dpd->project_dirname, + dpd->config_file); } if (GNUNET_OK != GNUNET_DISK_file_test (cfgname)) { -- cgit v1.2.3