mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
Direct leak of 32 byte(s) in 1 object(s) allocated from:
#0 0x7f7678ee863e in calloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10c63e)
#1 0x55f8c7b0fce5 in htable_default_alloc ccan/ccan/htable/htable.c:19
#2 0x55f8c7b1064f in double_table ccan/ccan/htable/htable.c:226
#3 0x55f8c7b10b19 in htable_add_ ccan/ccan/htable/htable.c:331
#4 0x55f8c7afac63 in scriptpubkeyset_add wallet/txfilter.c:30
#5 0x55f8c7afafce in txfilter_add_scriptpubkey wallet/txfilter.c:77
#6 0x55f8c7afb05f in txfilter_add_derkey wallet/txfilter.c:91
#7 0x55f8c7aa4d67 in init_txfilter lightningd/lightningd.c:482
#8 0x55f8c7aa52d8 in main lightningd/lightningd.c:721
#9 0x7f767889ab6a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x26b6a)
Direct leak of 16 byte(s) in 1 object(s) allocated from:
#0 0x7f05f389563e in calloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10c63e)
#1 0x55cac1e6bc99 in htable_default_alloc ccan/ccan/htable/htable.c:19
#2 0x55cac1e6c603 in double_table ccan/ccan/htable/htable.c:226
#3 0x55cac1e6cacd in htable_add_ ccan/ccan/htable/htable.c:331
#4 0x55cac1e56e48 in outpointset_add wallet/txfilter.c:61
#5 0x55cac1e57162 in outpointfilter_add wallet/txfilter.c:116
#6 0x55cac1e5ea3a in wallet_utxoset_add wallet/wallet.c:2365
#7 0x55cac1deddc2 in topo_add_utxos lightningd/chaintopology.c:603
#8 0x55cac1dedeac in add_tip lightningd/chaintopology.c:620
#9 0x55cac1dee2de in have_new_block lightningd/chaintopology.c:694
#10 0x55cac1deaab0 in process_rawblock lightningd/bitcoind.c:466
#11 0x55cac1de9fb4 in bcli_finished lightningd/bitcoind.c:214
#12 0x55cac1e6f5be in destroy_conn ccan/ccan/io/poll.c:244
#13 0x55cac1e6f5de in destroy_conn_close_fd ccan/ccan/io/poll.c:250
#14 0x55cac1e7baf5 in notify ccan/ccan/tal/tal.c:235
#15 0x55cac1e7bfe4 in del_tree ccan/ccan/tal/tal.c:397
#16 0x55cac1e7c370 in tal_free ccan/ccan/tal/tal.c:481
#17 0x55cac1e6dddd in io_close ccan/ccan/io/io.c:450
#18 0x55cac1e6fcf9 in io_loop ccan/ccan/io/poll.c:449
#19 0x55cac1dfac66 in io_loop_with_timers lightningd/io_loop_with_timers.c:24
#20 0x55cac1e0156b in main lightningd/lightningd.c:822
#21 0x7f05f3247b6a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x26b6a)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
154 lines
3.9 KiB
C
154 lines
3.9 KiB
C
#include "txfilter.h"
|
|
|
|
#include <bitcoin/script.h>
|
|
#include <ccan/build_assert/build_assert.h>
|
|
#include <ccan/crypto/ripemd160/ripemd160.h>
|
|
#include <ccan/mem/mem.h>
|
|
#include <common/memleak.h>
|
|
#include <common/pseudorand.h>
|
|
#include <common/utils.h>
|
|
#include <wallet/wallet.h>
|
|
|
|
static size_t scriptpubkey_hash(const u8 *out)
|
|
{
|
|
struct siphash24_ctx ctx;
|
|
siphash24_init(&ctx, siphash_seed());
|
|
siphash24_update(&ctx, out, tal_bytelen(out));
|
|
return siphash24_done(&ctx);
|
|
}
|
|
|
|
static const u8 *scriptpubkey_keyof(const u8 *out)
|
|
{
|
|
return out;
|
|
}
|
|
|
|
static int scriptpubkey_eq(const u8 *a, const u8 *b)
|
|
{
|
|
return memeq(a, tal_bytelen(a), b, tal_bytelen(b));
|
|
}
|
|
|
|
HTABLE_DEFINE_TYPE(u8, scriptpubkey_keyof, scriptpubkey_hash, scriptpubkey_eq, scriptpubkeyset);
|
|
|
|
struct txfilter {
|
|
struct scriptpubkeyset scriptpubkeyset;
|
|
};
|
|
|
|
struct outpointfilter_entry {
|
|
struct bitcoin_txid txid;
|
|
u32 outnum;
|
|
};
|
|
|
|
static size_t outpoint_hash(const struct outpointfilter_entry *out)
|
|
{
|
|
struct siphash24_ctx ctx;
|
|
siphash24_init(&ctx, siphash_seed());
|
|
siphash24_update(&ctx, &out->txid, sizeof(out->txid));
|
|
siphash24_u32(&ctx, out->outnum);
|
|
return siphash24_done(&ctx);
|
|
}
|
|
|
|
static bool outpoint_eq(const struct outpointfilter_entry *o1,
|
|
const struct outpointfilter_entry *o2)
|
|
{
|
|
return bitcoin_txid_eq(&o1->txid, &o2->txid) && o1->outnum == o2->outnum;
|
|
}
|
|
|
|
static const struct outpointfilter_entry *outpoint_keyof(const struct outpointfilter_entry *out)
|
|
{
|
|
return out;
|
|
}
|
|
|
|
HTABLE_DEFINE_TYPE(struct outpointfilter_entry, outpoint_keyof, outpoint_hash, outpoint_eq,
|
|
outpointset);
|
|
|
|
struct outpointfilter {
|
|
struct outpointset *set;
|
|
};
|
|
|
|
static void destroy_txfilter(struct txfilter *filter)
|
|
{
|
|
scriptpubkeyset_clear(&filter->scriptpubkeyset);
|
|
}
|
|
|
|
struct txfilter *txfilter_new(const tal_t *ctx)
|
|
{
|
|
struct txfilter *filter = tal(ctx, struct txfilter);
|
|
scriptpubkeyset_init(&filter->scriptpubkeyset);
|
|
tal_add_destructor(filter, destroy_txfilter);
|
|
return filter;
|
|
}
|
|
|
|
void txfilter_add_scriptpubkey(struct txfilter *filter, const u8 *script TAKES)
|
|
{
|
|
scriptpubkeyset_add(
|
|
&filter->scriptpubkeyset,
|
|
notleak(tal_dup_arr(filter, u8, script, tal_count(script), 0)));
|
|
}
|
|
|
|
void txfilter_add_derkey(struct txfilter *filter,
|
|
const u8 derkey[PUBKEY_CMPR_LEN])
|
|
{
|
|
u8 *skp, *p2sh;
|
|
|
|
skp = scriptpubkey_p2wpkh_derkey(tmpctx, derkey);
|
|
p2sh = scriptpubkey_p2sh(tmpctx, skp);
|
|
|
|
txfilter_add_scriptpubkey(filter, take(skp));
|
|
txfilter_add_scriptpubkey(filter, take(p2sh));
|
|
}
|
|
|
|
|
|
bool txfilter_match(const struct txfilter *filter, const struct bitcoin_tx *tx)
|
|
{
|
|
for (size_t i = 0; i < tx->wtx->num_outputs; i++) {
|
|
const u8 *oscript = bitcoin_tx_output_get_script(tmpctx, tx, i);
|
|
|
|
if (scriptpubkeyset_get(&filter->scriptpubkeyset, oscript))
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void outpointfilter_add(struct outpointfilter *of, const struct bitcoin_txid *txid, const u32 outnum)
|
|
{
|
|
struct outpointfilter_entry *op;
|
|
if (outpointfilter_matches(of, txid, outnum))
|
|
return;
|
|
/* Have to mark the entries as notleak since they'll not be
|
|
* pointed to by anything other than the htable */
|
|
op = notleak(tal(of->set, struct outpointfilter_entry));
|
|
op->txid = *txid;
|
|
op->outnum = outnum;
|
|
outpointset_add(of->set, op);
|
|
}
|
|
|
|
bool outpointfilter_matches(struct outpointfilter *of, const struct bitcoin_txid *txid, const u32 outnum)
|
|
{
|
|
struct outpointfilter_entry op;
|
|
op.txid = *txid;
|
|
op.outnum = outnum;
|
|
return outpointset_get(of->set, &op) != NULL;
|
|
}
|
|
|
|
void outpointfilter_remove(struct outpointfilter *of, const struct bitcoin_txid *txid, const u32 outnum)
|
|
{
|
|
struct outpointfilter_entry op;
|
|
op.txid = *txid;
|
|
op.outnum = outnum;
|
|
outpointset_del(of->set, &op);
|
|
}
|
|
|
|
static void destroy_outpointfilter(struct outpointfilter *opf)
|
|
{
|
|
outpointset_clear(opf->set);
|
|
}
|
|
|
|
struct outpointfilter *outpointfilter_new(tal_t *ctx)
|
|
{
|
|
struct outpointfilter *opf = tal(ctx, struct outpointfilter);
|
|
opf->set = tal(opf, struct outpointset);
|
|
outpointset_init(opf->set);
|
|
tal_add_destructor(opf, destroy_outpointfilter);
|
|
return opf;
|
|
}
|