gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet] branch master updated: -fix GNS API


From: gnunet
Subject: [gnunet] branch master updated: -fix GNS API
Date: Sat, 29 Oct 2022 11:31:07 +0200

This is an automated email from the git hooks/post-receive script.

martin-schanzenbach pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 914fd6ada -fix GNS API
914fd6ada is described below

commit 914fd6adac878abfa3050568ba02a1c57a150e8e
Author: Martin Schanzenbach <schanzen@gnunet.org>
AuthorDate: Sat Oct 29 18:31:00 2022 +0900

    -fix GNS API
---
 src/gns/gns.h                             | 13 ++++++------
 src/gns/gns_api.c                         | 16 ++++++++++++---
 src/gns/gnunet-service-gns.c              | 33 ++++++++++++++++++++++++-------
 src/identity/identity_api_suffix_lookup.c | 17 +++++++++-------
 4 files changed, 56 insertions(+), 23 deletions(-)

diff --git a/src/gns/gns.h b/src/gns/gns.h
index d824742ad..d882278f5 100644
--- a/src/gns/gns.h
+++ b/src/gns/gns.h
@@ -45,11 +45,6 @@ struct LookupMessage
    */
   uint32_t id GNUNET_PACKED;
 
-  /**
-   * Zone that is to be used for lookup
-   */
-  struct GNUNET_IDENTITY_PublicKey zone;
-
   /**
    * Local options for where to look for results
    * (an `enum GNUNET_GNS_LocalOptions` in NBO).
@@ -68,7 +63,13 @@ struct LookupMessage
    */
   int32_t type GNUNET_PACKED;
 
-  /* Followed by the zero-terminated name to look up */
+  /**
+   * Length of the zone key
+   */
+  uint32_t key_len GNUNET_PACKED;
+  /**
+   * Followed by the zone that is to be used for lookup
+   * Followed by the zero-terminated name to look up */
 };
 
 
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c
index 841a0d240..9e25154ef 100644
--- a/src/gns/gns_api.c
+++ b/src/gns/gns_api.c
@@ -354,6 +354,9 @@ GNUNET_GNS_lookup_limited (struct GNUNET_GNS_Handle *handle,
   struct LookupMessage *lookup_msg;
   struct GNUNET_GNS_LookupRequest *lr;
   size_t nlen;
+  size_t key_len;
+  ssize_t written;
+  char *buf;
 
   if (NULL == name)
   {
@@ -374,16 +377,23 @@ GNUNET_GNS_lookup_limited (struct GNUNET_GNS_Handle 
*handle,
   lr->lookup_proc = proc;
   lr->proc_cls = proc_cls;
   lr->r_id = handle->r_id_gen++;
+  key_len = GNUNET_IDENTITY_public_key_get_length (zone);
   lr->env = GNUNET_MQ_msg_extra (lookup_msg,
-                                 nlen,
+                                 nlen + key_len,
                                  GNUNET_MESSAGE_TYPE_GNS_LOOKUP);
+  buf = (char *) &lookup_msg[1];
   lookup_msg->id = htonl (lr->r_id);
   lookup_msg->options = htons ((uint16_t) options);
   lookup_msg->recursion_depth_limit
     = htons (recursion_depth_limit);
-  lookup_msg->zone = *zone;
+  lookup_msg->key_len = htonl (key_len);
+  written = GNUNET_IDENTITY_write_public_key_to_buffer (zone,
+                                                        buf,
+                                                        key_len);
+  GNUNET_assert (0 <= written);
+  buf += written;
   lookup_msg->type = htonl (type);
-  GNUNET_memcpy (&lookup_msg[1],
+  GNUNET_memcpy (buf,
                  name,
                  nlen);
   GNUNET_CONTAINER_DLL_insert (handle->lookup_head,
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index 6a11ec2ce..7e770ce5a 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -395,10 +395,11 @@ check_lookup (void *cls,
               const struct LookupMessage *l_msg)
 {
   size_t nlen;
+  size_t klen;
 
   (void) cls;
-  GNUNET_MQ_check_zero_termination (l_msg);
-  nlen = ntohs (l_msg->header.size) - sizeof(struct LookupMessage);
+  klen = ntohl (l_msg->key_len);
+  nlen = ntohs (l_msg->header.size) - sizeof(struct LookupMessage) - klen;
   if (nlen > GNUNET_DNSPARSER_MAX_NAME_LENGTH)
   {
     GNUNET_break (0);
@@ -420,19 +421,37 @@ handle_lookup (void *cls,
 {
   struct GnsClient *gc = cls;
   struct ClientLookupHandle *clh;
+  struct GNUNET_IDENTITY_PublicKey zone;
   const char *name;
+  size_t key_len;
+  size_t read;
 
   GNUNET_SERVICE_client_continue (gc->client);
-  name = (const char *) &sh_msg[1];
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Received LOOKUP `%s' message\n",
-              name);
+  key_len = ntohl (sh_msg->key_len);
   clh = GNUNET_new (struct ClientLookupHandle);
   GNUNET_CONTAINER_DLL_insert (gc->clh_head,
                                gc->clh_tail,
                                clh);
   clh->gc = gc;
   clh->request_id = sh_msg->id;
+  if ((GNUNET_SYSERR ==
+       GNUNET_IDENTITY_read_public_key_from_buffer (&sh_msg[1],
+                                                    key_len,
+                                                    &zone,
+                                                    &read)) ||
+      (read != key_len))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "LOOKUP: Failed to read zone key!");
+    send_lookup_response (clh,
+                          0,
+                          NULL);
+    return;
+  }
+  name = (const char *) &sh_msg[1] + key_len;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Received LOOKUP `%s' message\n",
+              name);
   if ((GNUNET_DNSPARSER_TYPE_A == ntohl (sh_msg->type)) &&
       (GNUNET_OK != v4_enabled))
   {
@@ -453,7 +472,7 @@ handle_lookup (void *cls,
                           NULL);
     return;
   }
-  clh->lookup = GNS_resolver_lookup (&sh_msg->zone,
+  clh->lookup = GNS_resolver_lookup (&zone,
                                      ntohl (sh_msg->type),
                                      name,
                                      (enum GNUNET_GNS_LocalOptions) ntohs (
diff --git a/src/identity/identity_api_suffix_lookup.c 
b/src/identity/identity_api_suffix_lookup.c
index fa6bd8310..4b459345d 100644
--- a/src/identity/identity_api_suffix_lookup.c
+++ b/src/identity/identity_api_suffix_lookup.c
@@ -138,13 +138,16 @@ handle_identity_update (void *cls, const struct 
UpdateMessage *um)
   tmp = (const char*) &um[1];
   str = (0 == name_len) ? NULL : tmp;
   memset (&private_key, 0, sizeof (private_key));
-  key_len = ntohs (um->header.size) - name_len;
-  GNUNET_assert (GNUNET_SYSERR !=
-                 GNUNET_IDENTITY_read_private_key_from_buffer (tmp + name_len,
-                                                               key_len,
-                                                               &private_key,
-                                                               &kb_read));
-  GNUNET_assert (key_len == kb_read);
+  key_len = ntohs (um->header.size) - name_len - sizeof (*um);
+  if (0 < key_len)
+  {
+    GNUNET_assert (GNUNET_SYSERR !=
+                   GNUNET_IDENTITY_read_private_key_from_buffer (tmp + 
name_len,
+                                                                 key_len,
+                                                                 &private_key,
+                                                                 &kb_read));
+    GNUNET_assert (key_len == kb_read);
+  }
   el->cb (el->cb_cls, &private_key, str);
   GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (el);
 }

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]