check return values, fix use of uninit memory on certain error handling paths
This commit is contained in:
parent
f43bac5894
commit
265fc74b65
@ -119,7 +119,7 @@ struct Reserve
|
|||||||
* Set to the API's handle during the operation.
|
* Set to the API's handle during the operation.
|
||||||
*/
|
*/
|
||||||
struct TALER_EXCHANGE_AdminAddIncomingHandle *aih;
|
struct TALER_EXCHANGE_AdminAddIncomingHandle *aih;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How much is left in this reserve.
|
* How much is left in this reserve.
|
||||||
*/
|
*/
|
||||||
@ -127,9 +127,9 @@ struct Reserve
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Index of this reserve in the #reserves array.
|
* Index of this reserve in the #reserves array.
|
||||||
*/
|
*/
|
||||||
unsigned int reserve_index;
|
unsigned int reserve_index;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ struct Coin
|
|||||||
* DLL of coins to withdraw.
|
* DLL of coins to withdraw.
|
||||||
*/
|
*/
|
||||||
struct Coin *prev;
|
struct Coin *prev;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set (by the interpreter) to the exchange's signature over the
|
* Set (by the interpreter) to the exchange's signature over the
|
||||||
* coin's public key.
|
* coin's public key.
|
||||||
@ -189,12 +189,12 @@ struct Coin
|
|||||||
* Array of denominations we expect to get from melt.
|
* Array of denominations we expect to get from melt.
|
||||||
*/
|
*/
|
||||||
struct TALER_Amount *denoms;
|
struct TALER_Amount *denoms;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The result of a #TALER_EXCHANGE_refresh_prepare() call
|
* The result of a #TALER_EXCHANGE_refresh_prepare() call
|
||||||
*/
|
*/
|
||||||
char *blob;
|
char *blob;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Size of @e blob
|
* Size of @e blob
|
||||||
*/
|
*/
|
||||||
@ -209,7 +209,7 @@ struct Coin
|
|||||||
* #GNUNET_YES if this coin is in the #invalid_coins_head DLL.
|
* #GNUNET_YES if this coin is in the #invalid_coins_head DLL.
|
||||||
*/
|
*/
|
||||||
int invalid;
|
int invalid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Index in the reserve's global array indicating which
|
* Index in the reserve's global array indicating which
|
||||||
* reserve this coin is to be retrieved. If the coin comes
|
* reserve this coin is to be retrieved. If the coin comes
|
||||||
@ -220,9 +220,9 @@ struct Coin
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Index of this coin in the #coins array.
|
* Index of this coin in the #coins array.
|
||||||
*/
|
*/
|
||||||
unsigned int coin_index;
|
unsigned int coin_index;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the coin has to be refreshed, this value indicates
|
* If the coin has to be refreshed, this value indicates
|
||||||
* how much is left on this coin
|
* how much is left on this coin
|
||||||
@ -397,13 +397,13 @@ static struct GNUNET_TIME_Absolute start_time;
|
|||||||
/**
|
/**
|
||||||
* Number of times #bennchmark_run has executed. Used
|
* Number of times #bennchmark_run has executed. Used
|
||||||
* to indicate when we consider us warm.
|
* to indicate when we consider us warm.
|
||||||
*/
|
*/
|
||||||
static unsigned long long warm;
|
static unsigned long long warm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of times #bennchmark_run should execute
|
* Number of times #bennchmark_run should execute
|
||||||
* before we shut down.
|
* before we shut down.
|
||||||
*/
|
*/
|
||||||
static unsigned int num_iterations;
|
static unsigned int num_iterations;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -428,8 +428,8 @@ static unsigned long long num_admin;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throw a weighted coin with @a probability.
|
* Throw a weighted coin with @a probability.
|
||||||
*
|
*
|
||||||
* @reurn #GNUNET_OK with @a probability, #GNUNET_NO with 1 - @a probability
|
* @reurn #GNUNET_OK with @a probability, #GNUNET_NO with 1 - @a probability
|
||||||
*/
|
*/
|
||||||
static unsigned int
|
static unsigned int
|
||||||
@ -697,7 +697,8 @@ refresh_coin (struct Coin *coin)
|
|||||||
unsigned int off;
|
unsigned int off;
|
||||||
|
|
||||||
GNUNET_break (NULL == coin->denoms);
|
GNUNET_break (NULL == coin->denoms);
|
||||||
TALER_amount_get_zero (currency, &curr);
|
GNUNET_assert (GNUNET_OK ==
|
||||||
|
TALER_amount_get_zero (currency, &curr));
|
||||||
left = coin->left;
|
left = coin->left;
|
||||||
off = 0;
|
off = 0;
|
||||||
while (0 != TALER_amount_cmp (&curr,
|
while (0 != TALER_amount_cmp (&curr,
|
||||||
@ -750,7 +751,7 @@ refresh_coin (struct Coin *coin)
|
|||||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
||||||
"Prepared blob of size %d for refresh\n",
|
"Prepared blob of size %d for refresh\n",
|
||||||
(unsigned int) blob_size);
|
(unsigned int) blob_size);
|
||||||
|
|
||||||
coin->blob = blob;
|
coin->blob = blob;
|
||||||
coin->blob_size = blob_size;
|
coin->blob_size = blob_size;
|
||||||
coin->denoms = denoms;
|
coin->denoms = denoms;
|
||||||
@ -846,31 +847,35 @@ spend_coin (struct Coin *coin,
|
|||||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
||||||
"Spending %d-th coin\n",
|
"Spending %d-th coin\n",
|
||||||
coin->coin_index);
|
coin->coin_index);
|
||||||
|
|
||||||
if (do_refresh)
|
if (do_refresh)
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Always spending 1 out of 8 KUDOS. To be improved by randomly
|
* Always spending 1 out of 8 KUDOS. To be improved by randomly
|
||||||
* picking the spent amount
|
* picking the spent amount
|
||||||
*/
|
*/
|
||||||
struct TALER_Amount one;
|
struct TALER_Amount one;
|
||||||
|
|
||||||
TALER_amount_get_zero (currency, &one);
|
GNUNET_assert (GNUNET_OK ==
|
||||||
|
TALER_amount_get_zero (currency, &one));
|
||||||
one.value = 1;
|
one.value = 1;
|
||||||
|
|
||||||
TALER_amount_subtract (&amount,
|
GNUNET_assert (GNUNET_SYSERR !=
|
||||||
&one,
|
TALER_amount_subtract (&amount,
|
||||||
&coin->pk->fee_deposit);
|
&one,
|
||||||
TALER_amount_subtract (&coin->left,
|
&coin->pk->fee_deposit));
|
||||||
&coin->pk->value,
|
GNUNET_assert (GNUNET_SYSERR !=
|
||||||
&one);
|
TALER_amount_subtract (&coin->left,
|
||||||
|
&coin->pk->value,
|
||||||
|
&one));
|
||||||
coin->refresh = GNUNET_YES;
|
coin->refresh = GNUNET_YES;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TALER_amount_subtract (&amount,
|
GNUNET_assert (GNUNET_SYSERR !=
|
||||||
&coin->pk->value,
|
TALER_amount_subtract (&amount,
|
||||||
&coin->pk->fee_deposit);
|
&coin->pk->value,
|
||||||
|
&coin->pk->fee_deposit));
|
||||||
coin->refresh = GNUNET_NO;
|
coin->refresh = GNUNET_NO;
|
||||||
}
|
}
|
||||||
memset (&dr, 0, sizeof (dr));
|
memset (&dr, 0, sizeof (dr));
|
||||||
@ -879,16 +884,16 @@ spend_coin (struct Coin *coin,
|
|||||||
dr.h_contract = h_contract;
|
dr.h_contract = h_contract;
|
||||||
TALER_JSON_hash (merchant_details,
|
TALER_JSON_hash (merchant_details,
|
||||||
&dr.h_wire);
|
&dr.h_wire);
|
||||||
|
|
||||||
dr.timestamp = GNUNET_TIME_absolute_hton (timestamp);
|
dr.timestamp = GNUNET_TIME_absolute_hton (timestamp);
|
||||||
dr.refund_deadline = GNUNET_TIME_absolute_hton (refund_deadline);
|
dr.refund_deadline = GNUNET_TIME_absolute_hton (refund_deadline);
|
||||||
dr.transaction_id = GNUNET_htonll (transaction_id);
|
dr.transaction_id = GNUNET_htonll (transaction_id);
|
||||||
|
|
||||||
TALER_amount_hton (&dr.amount_with_fee,
|
TALER_amount_hton (&dr.amount_with_fee,
|
||||||
&amount);
|
&amount);
|
||||||
TALER_amount_hton (&dr.deposit_fee,
|
TALER_amount_hton (&dr.deposit_fee,
|
||||||
&coin->pk->fee_deposit);
|
&coin->pk->fee_deposit);
|
||||||
|
|
||||||
GNUNET_CRYPTO_eddsa_key_get_public (&merchant_priv.eddsa_priv,
|
GNUNET_CRYPTO_eddsa_key_get_public (&merchant_priv.eddsa_priv,
|
||||||
&merchant_pub.eddsa_pub);
|
&merchant_pub.eddsa_pub);
|
||||||
dr.merchant = merchant_pub;
|
dr.merchant = merchant_pub;
|
||||||
@ -981,8 +986,9 @@ withdraw_coin (struct Coin *coin)
|
|||||||
coin_priv = GNUNET_CRYPTO_eddsa_key_create ();
|
coin_priv = GNUNET_CRYPTO_eddsa_key_create ();
|
||||||
coin->coin_priv.eddsa_priv = *coin_priv;
|
coin->coin_priv.eddsa_priv = *coin_priv;
|
||||||
GNUNET_free (coin_priv);
|
GNUNET_free (coin_priv);
|
||||||
TALER_amount_get_zero (currency,
|
GNUNET_assert (GNUNET_OK ==
|
||||||
&amount);
|
TALER_amount_get_zero (currency,
|
||||||
|
&amount));
|
||||||
amount.value = COIN_VALUE;
|
amount.value = COIN_VALUE;
|
||||||
GNUNET_assert (-1 != TALER_amount_cmp (&r->left,
|
GNUNET_assert (-1 != TALER_amount_cmp (&r->left,
|
||||||
&amount));
|
&amount));
|
||||||
@ -1061,12 +1067,13 @@ fill_reserve (struct Reserve *r)
|
|||||||
struct TALER_Amount reserve_amount;
|
struct TALER_Amount reserve_amount;
|
||||||
json_t *transfer_details;
|
json_t *transfer_details;
|
||||||
|
|
||||||
TALER_amount_get_zero (currency,
|
GNUNET_assert (GNUNET_OK ==
|
||||||
&reserve_amount);
|
TALER_amount_get_zero (currency,
|
||||||
|
&reserve_amount));
|
||||||
reserve_amount.value = RESERVE_VALUE;
|
reserve_amount.value = RESERVE_VALUE;
|
||||||
execution_date = GNUNET_TIME_absolute_get ();
|
execution_date = GNUNET_TIME_absolute_get ();
|
||||||
GNUNET_TIME_round_abs (&execution_date);
|
GNUNET_TIME_round_abs (&execution_date);
|
||||||
|
|
||||||
priv = GNUNET_CRYPTO_eddsa_key_create ();
|
priv = GNUNET_CRYPTO_eddsa_key_create ();
|
||||||
r->reserve_priv.eddsa_priv = *priv;
|
r->reserve_priv.eddsa_priv = *priv;
|
||||||
GNUNET_free (priv);
|
GNUNET_free (priv);
|
||||||
@ -1103,7 +1110,7 @@ benchmark_run (void *cls)
|
|||||||
unsigned int i;
|
unsigned int i;
|
||||||
int refresh;
|
int refresh;
|
||||||
struct Coin *coin;
|
struct Coin *coin;
|
||||||
|
|
||||||
benchmark_task = NULL;
|
benchmark_task = NULL;
|
||||||
/* First, always make sure all reserves are full */
|
/* First, always make sure all reserves are full */
|
||||||
if (NULL != empty_reserve_head)
|
if (NULL != empty_reserve_head)
|
||||||
@ -1255,7 +1262,7 @@ cert_cb (void *cls,
|
|||||||
fail ("Initializing denominations failed");
|
fail ("Initializing denominations failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
currency = GNUNET_strdup (_keys->denom_keys[0].value.currency);
|
currency = GNUNET_strdup (_keys->denom_keys[0].value.currency);
|
||||||
if (GNUNET_SYSERR ==
|
if (GNUNET_SYSERR ==
|
||||||
@ -1306,7 +1313,7 @@ do_shutdown (void *cls)
|
|||||||
for (i=0; i<COINS_PER_RESERVE * nreserves; i++)
|
for (i=0; i<COINS_PER_RESERVE * nreserves; i++)
|
||||||
{
|
{
|
||||||
struct Coin *coin = &coins[i];
|
struct Coin *coin = &coins[i];
|
||||||
|
|
||||||
if (NULL != coin->wsh)
|
if (NULL != coin->wsh)
|
||||||
{
|
{
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||||
@ -1524,7 +1531,7 @@ run (void *cls)
|
|||||||
{
|
{
|
||||||
struct Coin *coin;
|
struct Coin *coin;
|
||||||
unsigned int coin_index;
|
unsigned int coin_index;
|
||||||
|
|
||||||
coin_index = i * COINS_PER_RESERVE + j;
|
coin_index = i * COINS_PER_RESERVE + j;
|
||||||
coin = &coins[coin_index];
|
coin = &coins[coin_index];
|
||||||
coin->coin_index = coin_index;
|
coin->coin_index = coin_index;
|
||||||
@ -1532,7 +1539,7 @@ run (void *cls)
|
|||||||
invalidate_coin (coin);
|
invalidate_coin (coin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
|
ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
|
||||||
&rc);
|
&rc);
|
||||||
GNUNET_assert (NULL != ctx);
|
GNUNET_assert (NULL != ctx);
|
||||||
@ -1545,7 +1552,7 @@ run (void *cls)
|
|||||||
if (NULL == exchange)
|
if (NULL == exchange)
|
||||||
{
|
{
|
||||||
fail ("Failed to connect to the exchange!");
|
fail ("Failed to connect to the exchange!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1605,7 +1612,7 @@ main (int argc,
|
|||||||
if (run_exchange)
|
if (run_exchange)
|
||||||
{
|
{
|
||||||
char *wget;
|
char *wget;
|
||||||
|
|
||||||
proc = GNUNET_OS_start_process (GNUNET_NO,
|
proc = GNUNET_OS_start_process (GNUNET_NO,
|
||||||
GNUNET_OS_INHERIT_STD_ALL,
|
GNUNET_OS_INHERIT_STD_ALL,
|
||||||
NULL, NULL, NULL,
|
NULL, NULL, NULL,
|
||||||
|
@ -1042,7 +1042,8 @@ main (int argc,
|
|||||||
unixpath_admin_mode);
|
unixpath_admin_mode);
|
||||||
if (-1 == fh_admin)
|
if (-1 == fh_admin)
|
||||||
{
|
{
|
||||||
GNUNET_break (0 == close (fh));
|
if (-1 != fh)
|
||||||
|
GNUNET_break (0 == close (fh));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -342,7 +342,6 @@ handle_refresh_melt_json (struct MHD_Connection *connection,
|
|||||||
struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coin[TALER_CNC_KAPPA];
|
struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coin[TALER_CNC_KAPPA];
|
||||||
struct TALER_TransferPublicKeyP transfer_pub[TALER_CNC_KAPPA];
|
struct TALER_TransferPublicKeyP transfer_pub[TALER_CNC_KAPPA];
|
||||||
|
|
||||||
|
|
||||||
/* For the signature check, we hash most of the inputs together
|
/* For the signature check, we hash most of the inputs together
|
||||||
(except for the signatures on the coins). */
|
(except for the signatures on the coins). */
|
||||||
hash_context = GNUNET_CRYPTO_hash_context_start ();
|
hash_context = GNUNET_CRYPTO_hash_context_start ();
|
||||||
@ -362,7 +361,7 @@ handle_refresh_melt_json (struct MHD_Connection *connection,
|
|||||||
{
|
{
|
||||||
GNUNET_break_op (0);
|
GNUNET_break_op (0);
|
||||||
res = (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES;
|
res = (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES;
|
||||||
goto cleanup;
|
goto cleanup_hc;
|
||||||
}
|
}
|
||||||
GNUNET_CRYPTO_hash_context_read (hash_context,
|
GNUNET_CRYPTO_hash_context_read (hash_context,
|
||||||
&transfer_pub[i],
|
&transfer_pub[i],
|
||||||
@ -491,10 +490,14 @@ handle_refresh_melt_json (struct MHD_Connection *connection,
|
|||||||
if (NULL != coin_melt_details.coin_info.denom_sig.rsa_signature)
|
if (NULL != coin_melt_details.coin_info.denom_sig.rsa_signature)
|
||||||
GNUNET_CRYPTO_rsa_signature_free (coin_melt_details.coin_info.denom_sig.rsa_signature);
|
GNUNET_CRYPTO_rsa_signature_free (coin_melt_details.coin_info.denom_sig.rsa_signature);
|
||||||
cleanup_denoms:
|
cleanup_denoms:
|
||||||
for (j=0;j<num_newcoins;j++)
|
if (NULL != denom_pubs)
|
||||||
if (NULL != denom_pubs[j].rsa_public_key)
|
{
|
||||||
GNUNET_CRYPTO_rsa_public_key_free (denom_pubs[j].rsa_public_key);
|
for (j=0;j<num_newcoins;j++)
|
||||||
GNUNET_free (denom_pubs);
|
if (NULL != denom_pubs[j].rsa_public_key)
|
||||||
|
GNUNET_CRYPTO_rsa_public_key_free (denom_pubs[j].rsa_public_key);
|
||||||
|
GNUNET_free (denom_pubs);
|
||||||
|
}
|
||||||
|
cleanup_hc:
|
||||||
if (NULL != hash_context)
|
if (NULL != hash_context)
|
||||||
GNUNET_CRYPTO_hash_context_abort (hash_context);
|
GNUNET_CRYPTO_hash_context_abort (hash_context);
|
||||||
return res;
|
return res;
|
||||||
|
@ -491,6 +491,7 @@ test_melting (struct TALER_EXCHANGEDB_Session *session)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = GNUNET_SYSERR;
|
ret = GNUNET_SYSERR;
|
||||||
|
memset (ev_sigs, 0, sizeof (ev_sigs));
|
||||||
RND_BLK (&refresh_session);
|
RND_BLK (&refresh_session);
|
||||||
RND_BLK (&session_hash);
|
RND_BLK (&session_hash);
|
||||||
dkp = NULL;
|
dkp = NULL;
|
||||||
@ -672,7 +673,8 @@ test_melting (struct TALER_EXCHANGEDB_Session *session)
|
|||||||
ret = GNUNET_OK;
|
ret = GNUNET_OK;
|
||||||
drop:
|
drop:
|
||||||
for (cnt=0; cnt < MELT_NEW_COINS; cnt++)
|
for (cnt=0; cnt < MELT_NEW_COINS; cnt++)
|
||||||
GNUNET_CRYPTO_rsa_signature_free (ev_sigs[cnt].rsa_signature);
|
if (NULL != ev_sigs[cnt].rsa_signature)
|
||||||
|
GNUNET_CRYPTO_rsa_signature_free (ev_sigs[cnt].rsa_signature);
|
||||||
if (NULL != commit_coins)
|
if (NULL != commit_coins)
|
||||||
{
|
{
|
||||||
plugin->free_refresh_commit_coins (plugin->cls,
|
plugin->free_refresh_commit_coins (plugin->cls,
|
||||||
|
Loading…
Reference in New Issue
Block a user