summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-07-21 18:51:05 +0200
committerChristian Grothoff <christian@grothoff.org>2021-07-21 18:51:05 +0200
commit5828dfad1df1ff9c4f2cec18a9a85c87f7364930 (patch)
tree078f1f13310b32eff941d4bb7caf5fda2f352a8f /src
parent3721780f16f61727e0f29505a32c4aa43b53ed51 (diff)
downloadexchange-5828dfad1df1ff9c4f2cec18a9a85c87f7364930.tar.gz
exchange-5828dfad1df1ff9c4f2cec18a9a85c87f7364930.tar.bz2
exchange-5828dfad1df1ff9c4f2cec18a9a85c87f7364930.zip
fix NPE on key not found
Diffstat (limited to 'src')
-rw-r--r--src/exchange/taler-exchange-httpd_keys.c16
-rw-r--r--src/exchange/taler-exchange-httpd_keys.h6
-rw-r--r--src/exchange/taler-exchange-httpd_management_post_keys.c20
3 files changed, 31 insertions, 11 deletions
diff --git a/src/exchange/taler-exchange-httpd_keys.c b/src/exchange/taler-exchange-httpd_keys.c
index b703b2209..f6894a2a8 100644
--- a/src/exchange/taler-exchange-httpd_keys.c
+++ b/src/exchange/taler-exchange-httpd_keys.c
@@ -2152,7 +2152,7 @@ TEH_keys_get_handler (const struct TEH_RequestHandler *rh,
* @param[in,out] meta denomination type data to complete
* @return #GNUNET_OK on success
*/
-static int
+static enum GNUNET_GenericReturnValue
load_fees (const char *section_name,
struct TALER_EXCHANGEDB_DenominationKeyMetaData *meta)
{
@@ -2271,14 +2271,14 @@ load_fees (const char *section_name,
}
-int
+enum GNUNET_GenericReturnValue
TEH_keys_load_fees (const struct GNUNET_HashCode *h_denom_pub,
struct TALER_DenominationPublicKey *denom_pub,
struct TALER_EXCHANGEDB_DenominationKeyMetaData *meta)
{
struct TEH_KeyStateHandle *ksh;
struct HelperDenomination *hd;
- int ok;
+ enum GNUNET_GenericReturnValue ok;
ksh = get_key_state (true);
if (NULL == ksh)
@@ -2289,6 +2289,13 @@ TEH_keys_load_fees (const struct GNUNET_HashCode *h_denom_pub,
hd = GNUNET_CONTAINER_multihashmap_get (ksh->helpers->denom_keys,
h_denom_pub);
+ if (NULL == hd)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Denomination %s not known\n",
+ GNUNET_h2s (h_denom_pub));
+ return GNUNET_NO;
+ }
meta->start = hd->start_time;
meta->expire_withdraw = GNUNET_TIME_absolute_add (meta->start,
hd->validity_duration);
@@ -2298,8 +2305,7 @@ TEH_keys_load_fees (const struct GNUNET_HashCode *h_denom_pub,
denom_pub->rsa_public_key
= GNUNET_CRYPTO_rsa_public_key_dup (hd->denom_pub.rsa_public_key);
else
- denom_pub->rsa_public_key
- = NULL;
+ denom_pub->rsa_public_key = NULL;
return ok;
}
diff --git a/src/exchange/taler-exchange-httpd_keys.h b/src/exchange/taler-exchange-httpd_keys.h
index 2a74304e9..7494597a2 100644
--- a/src/exchange/taler-exchange-httpd_keys.h
+++ b/src/exchange/taler-exchange-httpd_keys.h
@@ -356,9 +356,11 @@ TEH_keys_management_get_handler (const struct TEH_RequestHandler *rh,
* to use to derive the section name of the configuration to use
* @param[out] denom_pub set to the denomination public key (to be freed by caller!)
* @param[out] meta denomination type data to complete
- * @return #GNUNET_OK on success
+ * @return #GNUNET_OK on success,
+ * #GNUNET_NO if @a h_denom_pub is not known
+ * #GNUNET_SYSERR on hard errors
*/
-int
+enum GNUNET_GenericReturnValue
TEH_keys_load_fees (const struct GNUNET_HashCode *h_denom_pub,
struct TALER_DenominationPublicKey *denom_pub,
struct TALER_EXCHANGEDB_DenominationKeyMetaData *meta);
diff --git a/src/exchange/taler-exchange-httpd_management_post_keys.c b/src/exchange/taler-exchange-httpd_management_post_keys.c
index a4e8ac35f..4fb65d414 100644
--- a/src/exchange/taler-exchange-httpd_management_post_keys.c
+++ b/src/exchange/taler-exchange-httpd_management_post_keys.c
@@ -147,17 +147,29 @@ add_keys (void *cls,
}
if (0 == qs)
{
- if (GNUNET_OK !=
- TEH_keys_load_fees (&akc->d_sigs[i].h_denom_pub,
- &denom_pub,
- &meta))
+ enum GNUNET_GenericReturnValue rv;
+
+ rv = TEH_keys_load_fees (&akc->d_sigs[i].h_denom_pub,
+ &denom_pub,
+ &meta);
+ switch (rv)
{
+ case GNUNET_SYSERR:
+ *mhd_ret = TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_EXCHANGE_GENERIC_BAD_CONFIGURATION,
+ GNUNET_h2s (&akc->d_sigs[i].h_denom_pub));
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ case GNUNET_NO:
*mhd_ret = TALER_MHD_reply_with_error (
connection,
MHD_HTTP_NOT_FOUND,
TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN,
GNUNET_h2s (&akc->d_sigs[i].h_denom_pub));
return GNUNET_DB_STATUS_HARD_ERROR;
+ case GNUNET_OK:
+ break;
}
}
else