Browse Source

Reentrancy

beta
jl777 7 years ago
parent
commit
be872ded56
  1. 1
      iguana/exchanges/LP_include.h
  2. 3
      iguana/exchanges/LP_nativeDEX.c
  3. 12
      iguana/exchanges/LP_ordermatch.c
  4. 7
      iguana/exchanges/LP_swap.c

1
iguana/exchanges/LP_include.h

@ -298,6 +298,7 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re
uint64_t LP_txfeecalc(struct iguana_info *coin,uint64_t txfee);
struct LP_address *_LP_address(struct iguana_info *coin,char *coinaddr);
int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t wiftaddr,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,struct iguana_msgtx *msgtx,char **signedtxp,bits256 *signedtxidp,struct vin_info *V,int32_t numinputs,char *rawtx,cJSON *vins,cJSON *privkeysjson);
void LP_butxo_swapfields_set(struct LP_utxoinfo *butxo);
int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int32_t duration);
struct LP_transaction *LP_transactionfind(struct iguana_info *coin,bits256 txid);
cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJSON *txobj);

3
iguana/exchanges/LP_nativeDEX.c

@ -26,7 +26,8 @@
// unduplicated bugs:
// swap cancel should cleanly cancel
// check for completed one being spent, prevent autxo reuse, add extra hash to keypair25519, sign, spv check
// check for completed one being spent
// prevent autxo reuse, add extra hash to keypair25519, sign, spv check
#include <stdio.h>
#include "LP_include.h"

12
iguana/exchanges/LP_ordermatch.c

@ -674,7 +674,7 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJ
char *LP_connectedalice(cJSON *argjson) // alice
{
cJSON *retjson; double bid,ask,price,qprice; int32_t pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo A,B,*autxo,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin;
cJSON *retjson; double bid,ask,price,qprice; int32_t pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo *autxo,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin;
if ( LP_quoteparse(&Q,argjson) < 0 )
clonestr("{\"error\":\"cant parse quote\"}");
if ( bits256_cmp(Q.desthash,G.LP_mypub25519) != 0 )
@ -685,8 +685,8 @@ char *LP_connectedalice(cJSON *argjson) // alice
printf("swap already pending\n");
return(clonestr("{\"error\":\"swap already pending\"}"));
}
autxo = &A;
butxo = &B;
autxo = calloc(1,sizeof(*autxo));
butxo = calloc(1,sizeof(*butxo));
LP_abutxo_set(autxo,butxo,&Q);
/*if ( (autxo= LP_utxopairfind(0,Q.txid,Q.vout,Q.txid2,Q.vout2)) != 0 && autxo->S.swap != 0 )
{
@ -798,7 +798,7 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr)
int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen)
{
char *method,*msg; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo A,B,*autxo,*butxo; struct iguana_info *coin; struct LP_address_utxo *utxos[1000]; struct LP_quoteinfo Q; int32_t retval = -1,max=(int32_t)(sizeof(utxos)/sizeof(*utxos));
char *method,*msg; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo *autxo,*butxo; struct iguana_info *coin; struct LP_address_utxo *utxos[1000]; struct LP_quoteinfo Q; int32_t retval = -1,max=(int32_t)(sizeof(utxos)/sizeof(*utxos));
if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"request") == 0 ||strcmp(method,"connect") == 0) )
{
printf("LP_tradecommand: check received %s\n",method);
@ -811,8 +811,8 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
return(-3);
}
price = ask;
autxo = &A;
butxo = &B;
autxo = calloc(1,sizeof(*autxo));
butxo = calloc(1,sizeof(*butxo));
LP_abutxo_set(autxo,butxo,&Q);
LP_butxo_swapfields(butxo);
if ( strcmp(method,"request") == 0 )

7
iguana/exchanges/LP_swap.c

@ -121,7 +121,10 @@ void basilisk_swap_finished(struct basilisk_swap *swap)
{
int32_t i;
if ( swap->utxo != 0 && swap->sentflag == 0 )
{
LP_availableset(swap->utxo);
LP_butxo_swapfields_set(swap->utxo);
}
swap->I.finished = (uint32_t)time(NULL);
// save to permanent storage
basilisk_rawtx_purge(&swap->bobdeposit);
@ -815,8 +818,6 @@ void LP_aliceloop(void *_swap)
}
}
}
basilisk_swap_finished(swap);
free(swap);
}
free(data);
if ( swap->N.pair >= 0 )
@ -824,6 +825,8 @@ void LP_aliceloop(void *_swap)
nn_close(swap->N.pair);
swap->N.pair = -1;
}
basilisk_swap_finished(swap);
free(swap);
G.LP_pendingswaps--;
}

Loading…
Cancel
Save