fixing segv
[oweals/gnunet.git] / src / block / plugin_block_dns.c
index 743747c8566d7e29c365bd66e3ea0230fae19c4e..e0e970e080093520123161ed6728f7f34f9fb8a6 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "platform.h"
 #include "plugin_block.h"
+#include "gnunet_block_dns.h"
 
 #define DEBUG_DHT GNUNET_NO
 
@@ -45,7 +46,7 @@
  * @return characterization of result
  */
 static enum GNUNET_BLOCK_EvaluationResult
-block_plugin_dht_evaluate (void *cls,
+block_plugin_dns_evaluate (void *cls,
                           enum GNUNET_BLOCK_Type type,
                           const GNUNET_HashCode *query,
                           struct GNUNET_CONTAINER_BloomFilter **bf,
@@ -60,9 +61,19 @@ block_plugin_dht_evaluate (void *cls,
   case GNUNET_BLOCK_TYPE_DNS:
     if (xquery_size != 0)
       return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
+
     if (reply_block_size == 0)
       return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
-    return GNUNET_BLOCK_EVALUATION_OK_LAST;
+
+    if (reply_block_size < sizeof(struct GNUNET_DNS_Record))
+      return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
+
+    const struct GNUNET_DNS_Record* rec = reply_block;
+    if(reply_block_size != (sizeof(struct GNUNET_DNS_Record) + rec->namelen - 1))
+      return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
+
+    /* How to decide whether there are no more? */
+    return GNUNET_BLOCK_EVALUATION_OK_MORE;
   default:
     return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
   }
@@ -81,7 +92,7 @@ block_plugin_dht_evaluate (void *cls,
  *         (or if extracting a key from a block of this type does not work)
  */
 static int
-block_plugin_dht_get_key (void *cls,
+block_plugin_dns_get_key (void *cls,
                          enum GNUNET_BLOCK_Type type,
                          const void *block,
                          size_t block_size,
@@ -89,14 +100,16 @@ block_plugin_dht_get_key (void *cls,
 {
   if (type != GNUNET_BLOCK_TYPE_DNS)
     return GNUNET_SYSERR;
-  return GNUNET_SYSERR;
+  const struct GNUNET_DNS_Record* rec = block;
+  GNUNET_CRYPTO_hash(rec->name, rec->namelen, key);
+  return GNUNET_OK;
 }
 
 /**
  * Entry point for the plugin.
  */
 void *
-libgnunet_plugin_block_dht_init (void *cls)
+libgnunet_plugin_block_dns_init (void *cls)
 {
   static enum GNUNET_BLOCK_Type types[] = 
     {
@@ -106,8 +119,8 @@ libgnunet_plugin_block_dht_init (void *cls)
   struct GNUNET_BLOCK_PluginFunctions *api;
 
   api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions));
-  api->evaluate = &block_plugin_dht_evaluate;
-  api->get_key = &block_plugin_dht_get_key;
+  api->evaluate = &block_plugin_dns_evaluate;
+  api->get_key = &block_plugin_dns_get_key;
   api->types = types;
   return api;
 }
@@ -117,7 +130,7 @@ libgnunet_plugin_block_dht_init (void *cls)
  * Exit point from the plugin.
  */
 void *
-libgnunet_plugin_block_dht_done (void *cls)
+libgnunet_plugin_block_dns_done (void *cls)
 {
   struct GNUNET_TRANSPORT_PluginFunctions *api = cls;