gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 02/05: fix not initialized variable


From: gnunet
Subject: [taler-anastasis] 02/05: fix not initialized variable
Date: Tue, 07 Apr 2020 01:02:14 +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 00457bbc2acd990702d070fd005fac6a504d1f72
Author: Dennis Neufeld <address@hidden>
AuthorDate: Mon Apr 6 17:24:25 2020 +0000

    fix not initialized variable
---
 src/backend/anastasis-httpd_policy_upload.c |  4 +-
 src/include/anastasis_database_plugin.h     |  4 +-
 src/stasis/plugin_anastasis_postgres.c      | 60 ++++++++++++++++++++++-------
 src/stasis/test_anastasis_db.c              | 11 ++++--
 4 files changed, 59 insertions(+), 20 deletions(-)

diff --git a/src/backend/anastasis-httpd_policy_upload.c 
b/src/backend/anastasis-httpd_policy_upload.c
index 8a3fe75..81ffe97 100644
--- a/src/backend/anastasis-httpd_policy_upload.c
+++ b/src/backend/anastasis-httpd_policy_upload.c
@@ -835,9 +835,9 @@ AH_handler_policy_post (struct MHD_Connection *connection,
       struct GNUNET_HashCode hc;
       enum ANASTASIS_DB_QueryStatus qs;
 
-      memset (&hc, 0, sizeof (hc));
       qs = db->lookup_account (db->cls,
-                               &accountPubP);
+                               &accountPubP,
+                               &hc);
       if (qs < 0)
         return handle_database_error (puc,
                                       qs);
diff --git a/src/include/anastasis_database_plugin.h 
b/src/include/anastasis_database_plugin.h
index 562f962..dd9df56 100644
--- a/src/include/anastasis_database_plugin.h
+++ b/src/include/anastasis_database_plugin.h
@@ -305,12 +305,14 @@ struct ANASTASIS_DatabasePlugin
   /**
   * @param cls closure
   * @param anastasis_pub account identifier
+  * @param recovery_data_hash[OUT] set to hash of @a recovery document
   * @return transaction status
   */
   enum ANASTASIS_DB_QueryStatus
   (*lookup_account)(void *cls,
                     const struct
-                    ANASTASIS_CRYPTO_AccountPublicKey *anastasis_pub);
+                    ANASTASIS_CRYPTO_AccountPublicKey *anastasis_pub,
+                    struct GNUNET_HashCode *recovery_data_hash);
 
   /**
  * Lookup pending payments by account.
diff --git a/src/stasis/plugin_anastasis_postgres.c 
b/src/stasis/plugin_anastasis_postgres.c
index 78fecff..e975316 100644
--- a/src/stasis/plugin_anastasis_postgres.c
+++ b/src/stasis/plugin_anastasis_postgres.c
@@ -1102,34 +1102,66 @@ postgres_get_key_share (void *cls,
 /**
 * @param cls closure
 * @param anastasis_pub account identifier
+* @param recovery_data_hash[OUT] set to hash of @a recovery document
 * @return transaction status
 */
 enum ANASTASIS_DB_QueryStatus
 postgres_lookup_account (void *cls,
                          const struct
-                         ANASTASIS_CRYPTO_AccountPublicKey *anastasis_pub)
+                         ANASTASIS_CRYPTO_AccountPublicKey *anastasis_pub,
+                         struct GNUNET_HashCode *recovery_data_hash)
 {
   struct PostgresClosure *pg = cls;
-  struct GNUNET_TIME_Absolute expiration_date;
   enum ANASTASIS_DB_QueryStatus qs;
   struct GNUNET_PQ_QueryParam params[] = {
     GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
     GNUNET_PQ_query_param_end
   };
-  struct GNUNET_PQ_ResultSpec rs[] = {
-    GNUNET_PQ_result_spec_absolute_time ("expiration_date",
-                                         &expiration_date),
-    GNUNET_PQ_result_spec_end
-  };
 
   check_connection (pg);
-  qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
-                                                 "user_select",
-                                                 params,
-                                                 rs);
+  postgres_preflight (pg);
+  {
+    struct GNUNET_PQ_ResultSpec rs[] = {
+      GNUNET_PQ_result_spec_auto_from_type ("recovery_data_hash",
+                                            recovery_data_hash),
+      GNUNET_PQ_result_spec_end
+    };
 
-  GNUNET_break (ANASTASIS_DB_STATUS_HARD_ERROR != qs);
+    qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+                                                   
"recoverydocument_select_hash",
+                                                   params,
+                                                   rs);
+  }
+  switch (qs)
+  {
+  case GNUNET_DB_STATUS_HARD_ERROR:
+    return ANASTASIS_DB_STATUS_HARD_ERROR;
+  case GNUNET_DB_STATUS_SOFT_ERROR:
+    GNUNET_break (0);
+    return ANASTASIS_DB_STATUS_SOFT_ERROR;
+  case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+    break; /* handle interesting case below */
+  case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+    return ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT;
+  default:
+    GNUNET_break (0);
+    return ANASTASIS_DB_STATUS_HARD_ERROR;
+  }
+
+  /* check if account exists */
+  {
+    struct GNUNET_TIME_Absolute expiration_date;
+    struct GNUNET_PQ_ResultSpec rs[] = {
+      GNUNET_PQ_result_spec_auto_from_type ("expiration_date",
+                                            &expiration_date),
+      GNUNET_PQ_result_spec_end
+    };
 
+    qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+                                                   "user_select",
+                                                   params,
+                                                   rs);
+  }
   switch (qs)
   {
   case GNUNET_DB_STATUS_HARD_ERROR:
@@ -1138,9 +1170,11 @@ postgres_lookup_account (void *cls,
     GNUNET_break (0);
     return ANASTASIS_DB_STATUS_SOFT_ERROR;
   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+    /* indicates: no account */
     return ANASTASIS_DB_STATUS_PAYMENT_REQUIRED;
   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
-    return ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT;
+    /* indicates: no backup */
+    return ANASTASIS_DB_STATUS_NO_RESULTS;
   default:
     GNUNET_break (0);
     return ANASTASIS_DB_STATUS_HARD_ERROR;
diff --git a/src/stasis/test_anastasis_db.c b/src/stasis/test_anastasis_db.c
index 2ae6536..5b2f535 100644
--- a/src/stasis/test_anastasis_db.c
+++ b/src/stasis/test_anastasis_db.c
@@ -193,6 +193,7 @@ run (void *cls)
   size_t keysharesize;
   const char *str = "AHV123456789";
   struct GNUNET_CRYPTO_EccSignaturePurpose purp;
+  struct GNUNET_HashCode r;
 
   GNUNET_CRYPTO_eddsa_private_key_from_string (str,
                                                sizeof (str),
@@ -263,10 +264,6 @@ run (void *cls)
                                       &paymentSecretP,
                                       rel_time));
 
-  FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
-          plugin->lookup_account (plugin->cls,
-                                  &accountPubP));
-
   FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
           plugin->store_truth (plugin->cls,
                                &uuid,
@@ -290,6 +287,12 @@ run (void *cls)
                                            sizeof (&recovery_data),
                                            &paymentSecretP,
                                            &docVersion));
+
+  FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
+          plugin->lookup_account (plugin->cls,
+                                  &accountPubP,
+                                  &r));
+
   /* FIXME: do we really get an escrow challenge?
   FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
           plugin->get_escrow_challenge (plugin->cls,

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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