check return values, fix use of uninit memory on certain error handling paths

This commit is contained in:
Christian Grothoff 2016-09-23 16:52:13 +02:00
parent f43bac5894
commit 265fc74b65
4 changed files with 65 additions and 52 deletions

View File

@ -697,7 +697,8 @@ refresh_coin (struct Coin *coin)
unsigned int off;
GNUNET_break (NULL == coin->denoms);
TALER_amount_get_zero (currency, &curr);
GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, &curr));
left = coin->left;
off = 0;
while (0 != TALER_amount_cmp (&curr,
@ -855,22 +856,26 @@ spend_coin (struct Coin *coin,
*/
struct TALER_Amount one;
TALER_amount_get_zero (currency, &one);
GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, &one));
one.value = 1;
TALER_amount_subtract (&amount,
&one,
&coin->pk->fee_deposit);
TALER_amount_subtract (&coin->left,
&coin->pk->value,
&one);
GNUNET_assert (GNUNET_SYSERR !=
TALER_amount_subtract (&amount,
&one,
&coin->pk->fee_deposit));
GNUNET_assert (GNUNET_SYSERR !=
TALER_amount_subtract (&coin->left,
&coin->pk->value,
&one));
coin->refresh = GNUNET_YES;
}
else
{
TALER_amount_subtract (&amount,
&coin->pk->value,
&coin->pk->fee_deposit);
GNUNET_assert (GNUNET_SYSERR !=
TALER_amount_subtract (&amount,
&coin->pk->value,
&coin->pk->fee_deposit));
coin->refresh = GNUNET_NO;
}
memset (&dr, 0, sizeof (dr));
@ -981,8 +986,9 @@ withdraw_coin (struct Coin *coin)
coin_priv = GNUNET_CRYPTO_eddsa_key_create ();
coin->coin_priv.eddsa_priv = *coin_priv;
GNUNET_free (coin_priv);
TALER_amount_get_zero (currency,
&amount);
GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency,
&amount));
amount.value = COIN_VALUE;
GNUNET_assert (-1 != TALER_amount_cmp (&r->left,
&amount));
@ -1061,8 +1067,9 @@ fill_reserve (struct Reserve *r)
struct TALER_Amount reserve_amount;
json_t *transfer_details;
TALER_amount_get_zero (currency,
&reserve_amount);
GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency,
&reserve_amount));
reserve_amount.value = RESERVE_VALUE;
execution_date = GNUNET_TIME_absolute_get ();
GNUNET_TIME_round_abs (&execution_date);

View File

@ -1042,7 +1042,8 @@ main (int argc,
unixpath_admin_mode);
if (-1 == fh_admin)
{
GNUNET_break (0 == close (fh));
if (-1 != fh)
GNUNET_break (0 == close (fh));
return 1;
}
}

View File

@ -342,7 +342,6 @@ handle_refresh_melt_json (struct MHD_Connection *connection,
struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coin[TALER_CNC_KAPPA];
struct TALER_TransferPublicKeyP transfer_pub[TALER_CNC_KAPPA];
/* For the signature check, we hash most of the inputs together
(except for the signatures on the coins). */
hash_context = GNUNET_CRYPTO_hash_context_start ();
@ -362,7 +361,7 @@ handle_refresh_melt_json (struct MHD_Connection *connection,
{
GNUNET_break_op (0);
res = (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES;
goto cleanup;
goto cleanup_hc;
}
GNUNET_CRYPTO_hash_context_read (hash_context,
&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)
GNUNET_CRYPTO_rsa_signature_free (coin_melt_details.coin_info.denom_sig.rsa_signature);
cleanup_denoms:
for (j=0;j<num_newcoins;j++)
if (NULL != denom_pubs[j].rsa_public_key)
GNUNET_CRYPTO_rsa_public_key_free (denom_pubs[j].rsa_public_key);
GNUNET_free (denom_pubs);
if (NULL != denom_pubs)
{
for (j=0;j<num_newcoins;j++)
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)
GNUNET_CRYPTO_hash_context_abort (hash_context);
return res;

View File

@ -491,6 +491,7 @@ test_melting (struct TALER_EXCHANGEDB_Session *session)
int ret;
ret = GNUNET_SYSERR;
memset (ev_sigs, 0, sizeof (ev_sigs));
RND_BLK (&refresh_session);
RND_BLK (&session_hash);
dkp = NULL;
@ -672,7 +673,8 @@ test_melting (struct TALER_EXCHANGEDB_Session *session)
ret = GNUNET_OK;
drop:
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)
{
plugin->free_refresh_commit_coins (plugin->cls,