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; 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,
@ -855,22 +856,26 @@ spend_coin (struct Coin *coin,
*/ */
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;
GNUNET_assert (GNUNET_SYSERR !=
TALER_amount_subtract (&amount, TALER_amount_subtract (&amount,
&one, &one,
&coin->pk->fee_deposit); &coin->pk->fee_deposit));
GNUNET_assert (GNUNET_SYSERR !=
TALER_amount_subtract (&coin->left, TALER_amount_subtract (&coin->left,
&coin->pk->value, &coin->pk->value,
&one); &one));
coin->refresh = GNUNET_YES; coin->refresh = GNUNET_YES;
} }
else else
{ {
GNUNET_assert (GNUNET_SYSERR !=
TALER_amount_subtract (&amount, TALER_amount_subtract (&amount,
&coin->pk->value, &coin->pk->value,
&coin->pk->fee_deposit); &coin->pk->fee_deposit));
coin->refresh = GNUNET_NO; coin->refresh = GNUNET_NO;
} }
memset (&dr, 0, sizeof (dr)); memset (&dr, 0, sizeof (dr));
@ -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);
GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (currency,
&amount); &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,8 +1067,9 @@ fill_reserve (struct Reserve *r)
struct TALER_Amount reserve_amount; struct TALER_Amount reserve_amount;
json_t *transfer_details; json_t *transfer_details;
GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (currency,
&reserve_amount); &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);

View File

@ -1042,6 +1042,7 @@ main (int argc,
unixpath_admin_mode); unixpath_admin_mode);
if (-1 == fh_admin) if (-1 == fh_admin)
{ {
if (-1 != fh)
GNUNET_break (0 == close (fh)); GNUNET_break (0 == close (fh));
return 1; 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_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:
if (NULL != denom_pubs)
{
for (j=0;j<num_newcoins;j++) for (j=0;j<num_newcoins;j++)
if (NULL != denom_pubs[j].rsa_public_key) if (NULL != denom_pubs[j].rsa_public_key)
GNUNET_CRYPTO_rsa_public_key_free (denom_pubs[j].rsa_public_key); GNUNET_CRYPTO_rsa_public_key_free (denom_pubs[j].rsa_public_key);
GNUNET_free (denom_pubs); 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;

View File

@ -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,6 +673,7 @@ 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++)
if (NULL != ev_sigs[cnt].rsa_signature)
GNUNET_CRYPTO_rsa_signature_free (ev_sigs[cnt].rsa_signature); GNUNET_CRYPTO_rsa_signature_free (ev_sigs[cnt].rsa_signature);
if (NULL != commit_coins) if (NULL != commit_coins)
{ {