fix NPE if denomination key not found

This commit is contained in:
Christian Grothoff 2015-09-21 15:39:59 +02:00
parent cf0249b443
commit 49739455b0
4 changed files with 60 additions and 15 deletions

View File

@ -609,6 +609,31 @@ connection_done (void *cls,
#endif
/**
* Function called for logging by MHD.
*
* @param cls closure, NULL
* @param fm format string (`printf()`-style)
* @param ap arguments to @a fm
*/
static void
handle_mhd_logs (void *cls,
const char *fm,
va_list ap)
{
char buf[2048];
vsnprintf (buf,
sizeof (buf),
fm,
ap);
GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
"libmicrohttpd",
"%s",
buf);
}
/**
* The main function of the taler-mint-httpd server ("the mint").
*
@ -665,6 +690,7 @@ main (int argc,
serve_port,
NULL, NULL,
&handle_mhd_request, NULL,
MHD_OPTION_EXTERNAL_LOGGER, &handle_mhd_logs, NULL,
MHD_OPTION_NOTIFY_COMPLETED, &handle_mhd_completion_callback, NULL,
MHD_OPTION_CONNECTION_TIMEOUT, connection_timeout,
#if HAVE_DEVELOPER

View File

@ -187,6 +187,12 @@ TMH_DB_execute_deposit (struct MHD_Connection *connection,
dki = TMH_KS_denomination_key_lookup (mks,
&deposit->coin.denom_pub,
TMH_KS_DKU_DEPOSIT);
if (NULL == dki)
{
TMH_KS_release (mks);
return TMH_RESPONSE_reply_arg_invalid (connection,
"denom_pub");
}
TALER_amount_ntoh (&value,
&dki->issue.properties.value);
TMH_KS_release (mks);
@ -386,6 +392,13 @@ execute_reserve_withdraw_transaction (struct MHD_Connection *connection,
tdki = TMH_KS_denomination_key_lookup (key_state,
&pos->details.withdraw->denom_pub,
TMH_KS_DKU_WITHDRAW);
if (NULL == tdki)
{
GNUNET_break (0);
TMH_plugin->rollback (TMH_plugin->cls,
session);
return TMH_RESPONSE_reply_internal_db_error (connection);
}
TALER_amount_ntoh (&value,
&tdki->issue.properties.value);
if (0 == (res & 2))
@ -587,6 +600,7 @@ refresh_accept_melts (struct MHD_Connection *connection,
const struct TMH_DB_MeltDetails *coin_details,
uint16_t oldcoin_index)
{
struct TALER_MINTDB_DenominationKeyIssueInformation *dk;
struct TALER_MINTDB_DenominationKeyInformationP *dki;
struct TALER_MINTDB_TransactionList *tl;
struct TALER_Amount coin_value;
@ -595,16 +609,15 @@ refresh_accept_melts (struct MHD_Connection *connection,
struct TALER_MINTDB_RefreshMelt melt;
int res;
dki = &TMH_KS_denomination_key_lookup (key_state,
&coin_details->coin_info.denom_pub,
TMH_KS_DKU_DEPOSIT)->issue;
if (NULL == dki)
dk = TMH_KS_denomination_key_lookup (key_state,
&coin_details->coin_info.denom_pub,
TMH_KS_DKU_DEPOSIT);
if (NULL == dk)
return (MHD_YES ==
TMH_RESPONSE_reply_arg_unknown (connection,
"denom_pub"))
? GNUNET_NO : GNUNET_SYSERR;
dki = &dk->issue;
TALER_amount_ntoh (&coin_value,
&dki->properties.value);
/* fee for THIS transaction; the melt amount includes the fee! */
@ -934,7 +947,7 @@ check_commitment (struct MHD_Connection *connection,
&commit_links[j].transfer_pub,
sizeof (struct TALER_TransferPublicKeyP)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"transfer keys do not match\n");
GNUNET_free (commit_links);
return send_melt_commitment_error (connection,
@ -966,7 +979,7 @@ check_commitment (struct MHD_Connection *connection,
&last_shared_secret,
sizeof (struct GNUNET_HashCode)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"shared secrets do not match\n");
GNUNET_free (commit_links);
return send_melt_commitment_error (connection,
@ -1041,7 +1054,7 @@ check_commitment (struct MHD_Connection *connection,
commit_coins[j].coin_ev,
buf_len)) )
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"blind envelope does not match for k=%u, old=%d\n",
off,
(int) j);
@ -1389,7 +1402,6 @@ handle_transfer_data (void *cls,
session_hash);
if (NULL == ldl)
{
GNUNET_break (0);
ctx->status = GNUNET_NO;
if (MHD_NO ==
TMH_RESPONSE_reply_json_pack (ctx->connection,
@ -1463,7 +1475,7 @@ TMH_DB_execute_refresh_link (struct MHD_Connection *connection,
for (i=0;i<ctx.num_sessions;i++)
TMH_plugin->free_link_data_list (TMH_plugin->cls,
ctx.sessions[i].ldl);
GNUNET_free (ctx.sessions);
GNUNET_free_non_null (ctx.sessions);
return res;
}

View File

@ -111,7 +111,7 @@ verify_and_execute_deposit (struct MHD_Connection *connection,
TMH_KS_release (key_state);
return TMH_DB_execute_deposit (connection,
deposit);
deposit);
}

View File

@ -115,9 +115,16 @@ handle_refresh_melt_binary (struct MHD_Connection *connection,
{
/* calculate contribution of the i-th melt by subtracting
the fee; add the rest to the total_melt value */
dki = &TMH_KS_denomination_key_lookup (key_state,
&coin_melt_details[i].coin_info.denom_pub,
TMH_KS_DKU_DEPOSIT)->issue;
dk = TMH_KS_denomination_key_lookup (key_state,
&coin_melt_details[i].coin_info.denom_pub,
TMH_KS_DKU_DEPOSIT);
if (NULL == dk)
{
GNUNET_break (0);
return TMH_RESPONSE_reply_arg_invalid (connection,
"denom_pub");
}
dki = &dk->issue;
TALER_amount_ntoh (&fee_melt,
&dki->properties.fee_refresh);
if (GNUNET_OK !=