]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Unify lt_dlopen() error handling
authorOndřej Surý <ondrej@isc.org>
Wed, 28 Oct 2020 14:25:44 +0000 (15:25 +0100)
committerMichał Kępień <michal@isc.org>
Wed, 28 Oct 2020 14:48:58 +0000 (15:48 +0100)
Make sure an error gets logged when any lt_dlopen() call in the source
tree fails.  Also make sure that NULL values returned by lt_dlerror()
are replaced with a generic error message to prevent passing NULL as an
argument for the %s format specifier.

bin/named/unix/dlz_dlopen_driver.c
lib/dns/dyndb.c

index fb9ce8d459ff0927c2784953470e4df0a706a5d7..0f8ff4d33c29a37464bf6ce8d0d3e47409a4dbb9 100644 (file)
@@ -235,9 +235,13 @@ dlopen_dlz_create(const char *dlzname, unsigned int argc, char *argv[],
 
        cd->dl_handle = lt_dlopenext(cd->dl_path);
        if (cd->dl_handle == NULL) {
+               const char *errmsg = lt_dlerror();
+               if (errmsg == NULL) {
+                       errmsg = "unknown error";
+               }
                dlopen_log(ISC_LOG_ERROR,
                           "dlz_dlopen failed to open library '%s': %s",
-                          cd->dl_path, lt_dlerror());
+                          cd->dl_path, errmsg);
                result = ISC_R_FAILURE;
                goto failed;
        }
index e35293ece62154b4478826547a02eb2c49c99667..38e320e4cc4bfabdd851406ec31d57d618c719dc 100644 (file)
@@ -95,7 +95,7 @@ load_symbol(lt_dlhandle handle, const char *filename, const char *symbol_name,
                isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
                              DNS_LOGMODULE_DYNDB, ISC_LOG_ERROR,
                              "failed to lookup symbol %s in "
-                             "dyndb module '%s': %s",
+                             "DynDB module '%s': %s",
                              symbol_name, filename, errmsg);
                return (ISC_R_FAILURE);
        }
@@ -128,6 +128,15 @@ load_library(isc_mem_t *mctx, const char *filename, const char *instname,
 
        handle = lt_dlopen(filename);
        if (handle == NULL) {
+               const char *errmsg = lt_dlerror();
+               if (errmsg == NULL) {
+                       errmsg = "unknown error";
+               }
+               isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
+                             DNS_LOGMODULE_DYNDB, ISC_LOG_ERROR,
+                             "failed to dlopen() DynDB instance '%s' driver "
+                             "'%s': %s",
+                             instname, filename, errmsg);
                CHECK(ISC_R_FAILURE);
        }