Hi again,

I reworked the original patch to contain fallback for older version of
nettle. It will work fine on more recent version (should be a bit faster
than original code), but still will compile for older libraries.

On 02/26/2018 09:12 PM, Petr Menšík wrote:
> Hi again,
> 
> We at Fedora use dynamic linking for all libraries. We had breakage of
> dnsmasq build more than once, because dnsmasq is using directly
> nettle_hash array. If its size changes, dynamic linker will refuse to
> link it. For that reason, accessing hash array directly makes trouble.
> There is however special function that looks like very similar to
> hash_find() of dnsmasq, that iterates the array internally. It requires
> nettle 3.4, but I think that is already old enough. It would help
> preventing any more linker conflict, if library data changes.
> 
> Do you think older library version should be supported as well?
> 
> Best regards,
> 
> 
> 
> _______________________________________________
> Dnsmasq-discuss mailing list
> Dnsmasq-discuss@lists.thekelleys.org.uk
> http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss
> 

-- 
Petr Menšík
Software Engineer
Red Hat, http://www.redhat.com/
email: pemen...@redhat.com  PGP: 65C6C973
From 1577a17cbbd27775fa8730a6547077456acca3d6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemen...@redhat.com>
Date: Mon, 26 Feb 2018 20:52:33 +0100
Subject: [PATCH] Do not use nettle_hashes directly, use function for hash
 lookup provided by the library. Provide fallback for older versions.

---
 src/crypto.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/src/crypto.c b/src/crypto.c
index 16ef1ca..dafd33d 100644
--- a/src/crypto.c
+++ b/src/crypto.c
@@ -106,25 +106,35 @@ static struct nettle_hash null_hash = {
   (nettle_hash_digest_func *) null_hash_digest
 };
 
-/* Find pointer to correct hash function in nettle library */
-const struct nettle_hash *hash_find(char *name)
+#ifndef nettle_hashes
+/* Since nettle 3.4 nettle_hashes is not exported as variable,
+ * but is DEFINE to a function.
+ * Previous versions lack nettle_lookup_hash(), provide it. */
+static const struct nettle_hash *nettle_lookup_hash(char *name)
 {
   int i;
-  
-  if (!name)
-    return NULL;
-  
+
   for (i = 0; nettle_hashes[i]; i++)
     {
       if (strcmp(nettle_hashes[i]->name, name) == 0)
 	return nettle_hashes[i];
     }
+  return NULL;
+}
+#endif
 
+/* Find pointer to correct hash function in nettle library */
+const struct nettle_hash *hash_find(char *name)
+{
+  if (!name)
+    return NULL;
+ 
   /* We provide a "null" hash which returns the input data as digest. */
-  if (strcmp(null_hash.name, name) == 0)
+  if (strcmp(null_hash.name, name) == 0) {
     return &null_hash;
-
-  return NULL;
+  } else {
+    return nettle_lookup_hash(name);
+  }
 }
 
 /* expand ctx and digest memory allocations if necessary and init hash function */
-- 
2.14.3

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss

Reply via email to