-coverity, fix shorten test
authorMartin Schanzenbach <mschanzenbach@posteo.de>
Fri, 29 Jun 2012 15:04:55 +0000 (15:04 +0000)
committerMartin Schanzenbach <mschanzenbach@posteo.de>
Fri, 29 Jun 2012 15:04:55 +0000 (15:04 +0000)
src/gns/gnunet-gns-proxy.c
src/gns/gnunet-gns.c
src/gns/gnunet-service-gns_resolver.c
src/gns/test_gns_dht_threepeer.c
src/gns/test_gns_simple_shorten.c

index 856d98f07bef3eb5fb1f8886612c019aaae04b0b..91fa852cc963a3e02415e45b71aa010676d6fb51 100644 (file)
@@ -1557,7 +1557,7 @@ add_handle_to_mhd (struct GNUNET_NETWORK_Handle *h, struct MHD_Daemon *daemon)
   struct sockaddr *addr;
   socklen_t len;
 
-  fd = dup (GNUNET_NETWORK_get_fd (h));
+  fd = GNUNET_NETWORK_get_fd (h);
   addr = GNUNET_NETWORK_get_addr (h);
   len = GNUNET_NETWORK_get_addrlen (h);
 
@@ -2593,7 +2593,13 @@ run (void *cls, char *const *args, const char *cfgfile,
 
   mhd_unix_sock_addr.sun_family = AF_UNIX;
   strcpy (mhd_unix_sock_addr.sun_path, proxy_sockfile);
-  unlink (proxy_sockfile);
+  if (0 != unlink (proxy_sockfile))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unable to unlink sockfile!\n");
+    return;
+  }
+
   len = strlen (proxy_sockfile) + sizeof(AF_UNIX);
 
   GNUNET_free (proxy_sockfile);
index 95733618c8d7b9fa174d7297376a903ae22d53f4..f859c915ad4ccdd4bee7d644ba119c5658fb39ea 100644 (file)
@@ -278,6 +278,8 @@ run (void *cls, char *const *args, const char *cfgfile,
   {
     GNUNET_GNS_get_authority(gns, auth_name, &process_auth_result, auth_name);
   }
+
+  GNUNET_CRYPTO_rsa_key_free (shorten_key);
   
   // FIXME: do work here...
   //GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
index f17ff7135160a0a5c305c4a34106b0689db315f5..57f147ba6fac94e5dbeaba8f3c1de61fd2bef491 100644 (file)
@@ -180,7 +180,7 @@ is_canonical(char* name)
   char* tok;
 
   ndup = GNUNET_strdup (name);
-  tok = strtok (ndup, ".");
+  strtok (ndup, ".");
 
   for (tok = strtok (NULL, "."); tok != NULL; tok = strtok (NULL, "."))
   {
@@ -3982,7 +3982,7 @@ process_zone_to_name_shorten_root (void *cls,
       strcpy (nsh->result, result);
   }
   
-  if (0 != strcmp (nsh->private_zone_name, ""))
+  if (NULL != nsh->private_zone)
   {
     /* backtrack authorities for names in priv zone */
     rh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle,
@@ -3991,7 +3991,7 @@ process_zone_to_name_shorten_root (void *cls,
                                    &process_zone_to_name_shorten_private,
                                    rh);
   }
-  else if (0 != strcmp (nsh->shorten_zone_name, ""))
+  else if (NULL != nsh->shorten_zone)
   {
     /* backtrack authorities for names in shorten zone */
     rh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle,
@@ -4084,15 +4084,15 @@ handle_delegation_ns_shorten (void* cls,
       strcpy (nsh->result, result);
 
   }
-  else if (GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone,
-                                        nsh->private_zone) == 0)
+  else if (NULL != nsh->private_zone)
   {
     /**
      * This is our zone append .gnunet unless name is empty
      * (it shouldn't be, usually FIXME what happens if we
      * shorten to our zone to a "" record??)
      */
-    if (0 != strcmp (nsh->private_zone_name, ""))
+    if (GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone,
+                                     nsh->private_zone) == 0)
     {
     
       sprintf (result, "%s.%s.%s",
@@ -4105,15 +4105,15 @@ handle_delegation_ns_shorten (void* cls,
         strcpy (nsh->result, result);
     }
   }
-  else if (GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone,
-                                        nsh->shorten_zone) == 0)
+  else if (NULL != nsh->shorten_zone)
   {
     /**
      * This is our zone append .gnunet unless name is empty
      * (it shouldn't be, usually FIXME what happens if we
      * shorten to our zone to a "" record??)
      */
-    if (0 != strcmp (nsh->shorten_zone_name, ""))
+    if (GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone,
+                                     nsh->shorten_zone) == 0)
     {
       sprintf (result, "%s.%s.%s",
                rh->name, nsh->private_zone_name, GNUNET_GNS_TLD);
index 46f2adba104882647124dae47bed0388779098e6..9a7a0bdf3c89e3e95fcf431f3869bc86fa4ebc8b 100644 (file)
@@ -161,7 +161,6 @@ on_lookup_result(void *cls, uint32_t rd_count,
 {
   int i;
   char* string_val;
-  const char* typename;
 
   if (rd_count == 0)
   {
@@ -175,7 +174,6 @@ on_lookup_result(void *cls, uint32_t rd_count,
     GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", (char*)cls);
     for (i=0; i<rd_count; i++)
     {
-      typename = GNUNET_NAMESTORE_number_to_typename (rd[i].record_type);
       string_val = GNUNET_NAMESTORE_value_to_string(rd[i].record_type,
                                                     rd[i].data,
                                                     rd[i].data_size);
index 0f4da9b6c87f1b27a2d2ec6c27e6ffd75d483fbe..84a1dd71fbff9a3e01d37943f665f5b5f1508865 100644 (file)
@@ -75,6 +75,14 @@ static struct GNUNET_GNS_Handle *gns_handle;
 
 const struct GNUNET_CONFIGURATION_Handle *cfg;
 
+struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded priv_pkey;
+struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded short_pkey;
+struct GNUNET_CRYPTO_RsaPrivateKey *priv_key;
+struct GNUNET_CRYPTO_RsaPrivateKey *short_key;
+
+struct GNUNET_CRYPTO_ShortHashCode priv_zone;
+struct GNUNET_CRYPTO_ShortHashCode short_zone;
+
 /**
  * Check whether peers successfully shut down.
  */
@@ -153,7 +161,10 @@ commence_testing (void *cls, int32_t success, const char *emsg)
     return;
   }
 
-  GNUNET_GNS_shorten(gns_handle, TEST_DOMAIN, &process_shorten_result,
+  GNUNET_GNS_shorten(gns_handle, TEST_DOMAIN,
+                     &priv_zone,
+                     &short_zone,
+                     &process_shorten_result,
                      TEST_DOMAIN);
   
 }
@@ -200,6 +211,8 @@ do_shorten(void *cls, const struct GNUNET_PeerIdentity *id,
   struct GNUNET_CRYPTO_ShortHashCode alice_hash;
   struct GNUNET_CRYPTO_RsaSignature *sig;
   char* our_keyfile;
+  char* private_keyfile;
+  char* shorten_keyfile;
 
   cfg = _cfg;
 
@@ -222,16 +235,46 @@ do_shorten(void *cls, const struct GNUNET_PeerIdentity *id,
     ok = -1;
     return;
   }
+  
+  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
+                                                            "SHORTEN_ZONEKEY",
+                                                            &shorten_keyfile))
+  {
+    GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+               "Failed to get shorten zone key from cfg\n");
+    ok = -1;
+    return;
+  }
+  
+  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
+                                                            "PRIVATE_ZONEKEY",
+                                                            &private_keyfile))
+  {
+    GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+               "Failed to get private zone key from cfg\n");
+    ok = -1;
+    return;
+  }
 
   our_key = GNUNET_CRYPTO_rsa_key_create_from_file (our_keyfile);
   GNUNET_free(our_keyfile);
 
   bob_key = GNUNET_CRYPTO_rsa_key_create_from_file (KEYFILE_BOB);
   alice_key = GNUNET_CRYPTO_rsa_key_create_from_file (KEYFILE_ALICE);
+  priv_key = GNUNET_CRYPTO_rsa_key_create_from_file (private_keyfile);
+  short_key = GNUNET_CRYPTO_rsa_key_create_from_file (shorten_keyfile);
+
+  GNUNET_free(shorten_keyfile);
+  GNUNET_free(private_keyfile);
   
   GNUNET_CRYPTO_rsa_key_get_public (our_key, &our_pkey);
   GNUNET_CRYPTO_rsa_key_get_public (alice_key, &alice_pkey);
   GNUNET_CRYPTO_rsa_key_get_public (bob_key, &bob_pkey);
+  GNUNET_CRYPTO_rsa_key_get_public (priv_key, &priv_pkey);
+  GNUNET_CRYPTO_rsa_key_get_public (short_key, &short_pkey);
+
+  GNUNET_CRYPTO_short_hash(&priv_pkey, sizeof(priv_pkey), &priv_zone);
+  GNUNET_CRYPTO_short_hash(&short_pkey, sizeof(short_pkey), &short_zone);
 
   struct GNUNET_NAMESTORE_RecordData rd;
   char* ip = TEST_IP;
@@ -308,6 +351,8 @@ do_shorten(void *cls, const struct GNUNET_PeerIdentity *id,
   GNUNET_CRYPTO_rsa_key_free(our_key);
   GNUNET_CRYPTO_rsa_key_free(bob_key);
   GNUNET_CRYPTO_rsa_key_free(alice_key);
+  GNUNET_CRYPTO_rsa_key_free(priv_key);
+  GNUNET_CRYPTO_rsa_key_free(short_key);
 }
 
 static void