gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 01/04: fix memory leak in stasis, cleanup


From: gnunet
Subject: [taler-anastasis] 01/04: fix memory leak in stasis, cleanup
Date: Wed, 21 Oct 2020 15:36:43 +0200

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

dennis-neufeld pushed a commit to branch master
in repository anastasis.

commit a2a2379a86348583ec4018bf263f2c976ad9cc7d
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Wed Oct 21 12:36:19 2020 +0200

    fix memory leak in stasis, cleanup
---
 src/backend/anastasis-httpd_policy.c    |   2 +-
 src/include/anastasis_database_plugin.h |  27 ++---
 src/stasis/anastasis_db_plugin.c        |   2 +
 src/stasis/plugin_anastasis_postgres.c  |  27 +++--
 src/stasis/test_anastasis_db.c          | 182 +++++++++-----------------------
 5 files changed, 80 insertions(+), 160 deletions(-)

diff --git a/src/backend/anastasis-httpd_policy.c 
b/src/backend/anastasis-httpd_policy.c
index b2bf8a9..4cd0f30 100644
--- a/src/backend/anastasis-httpd_policy.c
+++ b/src/backend/anastasis-httpd_policy.c
@@ -80,9 +80,9 @@ AH_return_policy (struct MHD_Connection *connection,
     }
     qs = db->get_recovery_document (db->cls,
                                     account_pub,
+                                    version,
                                     &account_sig,
                                     &recovery_data_hash,
-                                    version,
                                     &res_recovery_data_size,
                                     &res_recovery_data);
   }
diff --git a/src/include/anastasis_database_plugin.h 
b/src/include/anastasis_database_plugin.h
index f2c3e99..ebaa810 100644
--- a/src/include/anastasis_database_plugin.h
+++ b/src/include/anastasis_database_plugin.h
@@ -200,26 +200,27 @@ struct ANASTASIS_DatabasePlugin
                              uint32_t *version);
 
   /**
-   * Fetch recovery document for user.
-   *
-   * @param cls closure
-   * @param anastasis_pub public key of the user's account
-   * @param account_sig signature
-   * @param recovery_data_hash hash of the current recovery data
-   * @param version[OUT] set to the version number of the policy the user 
requested
-   * @param data_size size of data blob
-   * @param data blob which contains the recovery document
-   * @return transaction status
-   */
+ * Fetch recovery document for user according given version.
+ *
+ * @param cls closure
+ * @param anastasis_pub public key of the user's account
+ * @param version the version number of the policy the user requests
+ * @param account_sig[OUT] signature
+ * @param recovery_data_hash[OUT] hash of the current recovery data
+ * @param data_size[OUT] size of data blob
+ * @param data[OUT] blob which contains the recovery document
+ * @return transaction status
+ */
   enum ANASTASIS_DB_QueryStatus
   (*get_recovery_document)(void *cls,
                            const struct
-                           ANASTASIS_CRYPTO_AccountPublicKeyP *anastasis_pub,
+                           ANASTASIS_CRYPTO_AccountPublicKeyP *
+                           anastasis_pub,
+                           uint32_t version,
                            struct
                            ANASTASIS_AccountSignatureP *account_sig,
                            struct
                            GNUNET_HashCode *recovery_data_hash,
-                           uint32_t version,
                            size_t *data_size,
                            void **data);
 
diff --git a/src/stasis/anastasis_db_plugin.c b/src/stasis/anastasis_db_plugin.c
index b0ebf02..8708cfb 100644
--- a/src/stasis/anastasis_db_plugin.c
+++ b/src/stasis/anastasis_db_plugin.c
@@ -54,6 +54,7 @@ ANASTASIS_DB_plugin_load (const struct 
GNUNET_CONFIGURATION_Handle *cfg)
                           "libanastasis_plugin_db_%s",
                           plugin_name);
   GNUNET_free (plugin_name);
+  plugin_name = NULL;
   cfg_dup = GNUNET_CONFIGURATION_dup (cfg);
   plugin = GNUNET_PLUGIN_load (lib_name, cfg_dup);
   if (NULL != plugin)
@@ -81,6 +82,7 @@ ANASTASIS_DB_plugin_unload (struct ANASTASIS_DatabasePlugin 
*plugin)
   GNUNET_assert (NULL == GNUNET_PLUGIN_unload (lib_name,
                                                plugin));
   GNUNET_free (lib_name);
+  lib_name = NULL;
 }
 
 
diff --git a/src/stasis/plugin_anastasis_postgres.c 
b/src/stasis/plugin_anastasis_postgres.c
index 70f2e83..e481194 100644
--- a/src/stasis/plugin_anastasis_postgres.c
+++ b/src/stasis/plugin_anastasis_postgres.c
@@ -985,6 +985,7 @@ postgres_record_recdoc_payment (void *cls,
   }
 }
 
+
 /**
  * Store payment for challenge.
  *
@@ -1016,9 +1017,6 @@ postgres_record_challenge_payment (void *cls,
   /*dummy funcion to check if truth is available*/
   void *truth;
   size_t truth_size;
-  char *truth_mime;
-  char *method;
-
 
   {
     // because of constraint at truth_id, first we have to verify
@@ -1031,10 +1029,6 @@ postgres_record_challenge_payment (void *cls,
       GNUNET_PQ_result_spec_variable_size ("encrypted_truth",
                                            &truth,
                                            &truth_size),
-      GNUNET_PQ_result_spec_string ("truth_mime",
-                                    &truth_mime),
-      GNUNET_PQ_result_spec_string ("method",
-                                    &method),
       GNUNET_PQ_result_spec_end
     };
     qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
@@ -1045,6 +1039,9 @@ postgres_record_challenge_payment (void *cls,
     {
       return qs;
     }
+    // free truth because not not needed
+    if (NULL != truth)
+      GNUNET_free (truth);
   }
 
   if (GNUNET_OK != begin_transaction (pg,
@@ -1091,6 +1088,8 @@ postgres_record_challenge_payment (void *cls,
 
   return ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT;
 }
+
+
 /**
  * Check payment identifier. Used to check if a payment identifier given by
  * the user is valid (existing and paid).
@@ -1506,15 +1505,15 @@ postgres_get_latest_recovery_document (void *cls,
 
 
 /**
- * Fetch recovery document for user.
+ * Fetch recovery document for user according given version.
  *
  * @param cls closure
  * @param anastasis_pub public key of the user's account
- * @param account_sig signature
- * @param recovery_data_hash hash of the current recovery data
- * @param version[OUT] set to the version number of the policy the user 
requested
- * @param data_size size of data blob
- * @param data blob which contains the recovery document
+ * @param version the version number of the policy the user requests
+ * @param account_sig[OUT] signature
+ * @param recovery_data_hash[OUT] hash of the current recovery data
+ * @param data_size[OUT] size of data blob
+ * @param data[OUT] blob which contains the recovery document
  * @return transaction status
  */
 enum ANASTASIS_DB_QueryStatus
@@ -1522,11 +1521,11 @@ postgres_get_recovery_document (void *cls,
                                 const struct
                                 ANASTASIS_CRYPTO_AccountPublicKeyP *
                                 anastasis_pub,
+                                uint32_t version,
                                 struct
                                 ANASTASIS_AccountSignatureP *account_sig,
                                 struct
                                 GNUNET_HashCode *recovery_data_hash,
-                                uint32_t version,
                                 size_t *data_size,
                                 void **data)
 
diff --git a/src/stasis/test_anastasis_db.c b/src/stasis/test_anastasis_db.c
index f283105..be9da90 100644
--- a/src/stasis/test_anastasis_db.c
+++ b/src/stasis/test_anastasis_db.c
@@ -50,91 +50,6 @@ static int result;
  */
 static struct ANASTASIS_DatabasePlugin *plugin;
 
-/**
- * Payment Secret for the test, set to a random value
- */
-static struct ANASTASIS_PaymentSecretP paymentSecretP;
-
-/**
- * User public key, set to a random value
- */
-static struct ANASTASIS_CRYPTO_AccountPublicKeyP accountPubP;
-
-/**
- * User private key
- */
-static struct ANASTASIS_CRYPTO_AccountPrivateKeyP accountPrivP;
-
-/**
- * Signature
- */
-static struct ANASTASIS_AccountSignatureP accountSig;
-
-/**
- * Signature
- */
-struct ANASTASIS_AccountSignatureP res_account_sig;
-
-/**
- * Hash of the recovery document to be uploaded
- */
-struct GNUNET_HashCode recoveryDataHash;
-
-/**
- * Hash of the current recovery document
- */
-struct GNUNET_HashCode res_recovery_data_hash;
-
-/**
- * How many posts are paid by the payment
- */
-static unsigned int post_counter;
-
-/**
- * Recoverydata which is stored into the Database, set to a random value
- */
-static void *recovery_data;
-
-/**
- * Recovery_data for the select test
- */
-static void *res_recovery_data;
-
-/**
- * Truthdata which is stored into the Database, set to a random value
- */
-static void *truth_data;
-
-/**
- * Keyshare which is stored into the Database, set to a random value
- */
-static void *key_share;
-
-/**
- * Keyshare for the select test
- */
-static void *res_key_share;
-
-/**
- * Mime-type of truth
- */
-static char *mime_type;
-
-/**
- * Method
- */
-static char *method;
-
-/**
- * Version of a Recoverydocument
- */
-static uint32_t docVersion;
-
-/**
- * Version of the latest Recoverydocument
- */
-static uint32_t res_version;
-
 
 /**
  * Main function that will be run by the scheduler.
@@ -166,70 +81,59 @@ run (void *cls)
     return;
   }
 
-  static uint32_t recversion = 1;
+  struct ANASTASIS_PaymentSecretP paymentSecretP;
+  struct ANASTASIS_CRYPTO_AccountPublicKeyP accountPubP;
+  struct ANASTASIS_AccountSignatureP accountSig;
+  struct ANASTASIS_AccountSignatureP res_account_sig;
+  struct GNUNET_HashCode recoveryDataHash;
+  struct GNUNET_HashCode res_recovery_data_hash;
+  struct GNUNET_HashCode r;
+  struct GNUNET_TIME_Relative challenge_expiration;
+  struct GNUNET_TIME_Relative rel_time;
+  struct ANASTASIS_CRYPTO_TruthPublicKeyP truth_public_key;
+  struct ANASTASIS_CRYPTO_NonceP truth_nonce;
+  unsigned int post_counter;
+  char *mime_type;
+  char *method;
+  uint32_t docVersion;
+  uint32_t res_version;
   size_t recoverydatasize;
   size_t keysharesize;
+  void *res_recovery_data = NULL;
+  void *res_key_share = NULL;
+  bool paid;
+  bool valid_counter;
+  uint32_t recversion = 1;
+  unsigned char aes_gcm_tag[16];
   const char *str = "AHV123456789";
-  struct GNUNET_HashCode r;
+  const char *recovery_data = "RECOVERY_DATA";
+  const char *truth_data = "TRUTH_DATA";
+  const char *key_share = "KEY_SHARE";
+  uint64_t challenge_code = 1234;
+
   struct ANASTASIS_UploadSignaturePS usp = {
     .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST),
     .purpose.size = htonl (sizeof (usp))
   };
-  uint64_t challenge_code = 1234;
 
-  struct GNUNET_TIME_Relative challenge_expiration;
   challenge_expiration = GNUNET_TIME_UNIT_HOURS;
-
-  GNUNET_CRYPTO_eddsa_private_key_from_string (str,
-                                               sizeof (str),
-                                               &accountPrivP.priv);
-
-  GNUNET_CRYPTO_eddsa_key_get_public (&accountPrivP.priv,
-                                      &accountPubP.pub);
-
-  int rec_val = 100;
-  recovery_data = &rec_val;
-  RND_BLK (recovery_data);
-
+  memset (&accountPubP, 1, sizeof (accountPubP));
+  memset (&accountSig, 2, sizeof (accountSig));
   GNUNET_CRYPTO_hash (recovery_data,
-                      sizeof (recovery_data),
+                      strlen (recovery_data),
                       &recoveryDataHash);
-
-  GNUNET_CRYPTO_eddsa_sign (&accountPrivP.priv,
-                            &usp,
-                            &accountSig.eddsa_sig);
   RND_BLK (&paymentSecretP);
-
-  int truth_val = 300;
-  truth_data = &truth_val;
-  RND_BLK (truth_data);
-
-  int key_val = 300;
-  key_share = &key_val;
-  RND_BLK (key_share);
-
-  unsigned char aes_gcm_tag[16];
   RND_BLK (&aes_gcm_tag);
-
-  bool paid;
-  bool valid_counter;
   post_counter = 2;
   mime_type = "Picture";
   method = "Methode";
   TALER_string_to_amount ("EUR:30",&amount);
 
-  struct ANASTASIS_CRYPTO_TruthPublicKeyP truth_public_key;
-  struct ANASTASIS_CRYPTO_NonceP truth_nonce;
   GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
                               &truth_nonce,
                               sizeof (struct ANASTASIS_CRYPTO_NonceP));
   ANASTASIS_CRYPTO_truth_public_key_derive (&truth_nonce,
                                             &truth_public_key);
-
-  uint32_t nonce;
-  RND_BLK (&nonce);
-
-  struct GNUNET_TIME_Relative rel_time;
   rel_time = GNUNET_TIME_UNIT_MONTHS;
 
   GNUNET_assert (GNUNET_OK ==
@@ -240,10 +144,10 @@ run (void *cls)
   FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
           plugin->store_truth (plugin->cls,
                                &truth_public_key,
-                               "key_share_data",
+                               key_share,
                                mime_type,
                                "encrypted_truth",
-                               sizeof ("encrypted_truth"),
+                               strlen ("encrypted_truth"),
                                method,
                                rel_time));
 
@@ -301,8 +205,8 @@ run (void *cls)
                                            &accountPubP,
                                            &accountSig,
                                            &recoveryDataHash,
-                                           &recovery_data,
-                                           sizeof (&recovery_data),
+                                           recovery_data,
+                                           strlen (recovery_data),
                                            &paymentSecretP,
                                            &docVersion));
 
@@ -316,15 +220,25 @@ run (void *cls)
                                  &truth_public_key,
                                  &res_key_share,
                                  &keysharesize));
+  FAILIF (0 != memcmp (res_key_share,
+                       key_share,
+                       strlen (key_share)));
+  GNUNET_free (res_key_share);
+  res_key_share = NULL;
 
   FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
           plugin->get_recovery_document (plugin->cls,
                                          &accountPubP,
+                                         recversion,
                                          &res_account_sig,
                                          &res_recovery_data_hash,
-                                         recversion,
                                          &recoverydatasize,
                                          &res_recovery_data));
+  FAILIF (0 != memcmp (res_recovery_data,
+                       recovery_data,
+                       strlen (recovery_data)));
+  GNUNET_free (res_recovery_data);
+  res_recovery_data = NULL;
 
   FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
           plugin->get_latest_recovery_document (plugin->cls,
@@ -334,6 +248,11 @@ run (void *cls)
                                                 &recoverydatasize,
                                                 &res_recovery_data,
                                                 &res_version));
+  FAILIF (0 != memcmp (res_recovery_data,
+                       recovery_data,
+                       strlen (recovery_data)));
+  GNUNET_free (res_recovery_data);
+  res_recovery_data = NULL;
 
 
   FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
@@ -363,7 +282,6 @@ run (void *cls)
                                          &truth_public_key,
                                          challenge_code));
 
-
   if (-1 == result)
     result = 0;
 

-- 
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]