bitcoin: use ccan/mem instead of rolling own check_mem function.

Reported-by: John Newbery
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2015-10-26 21:05:28 +10:30
parent be58e45ee4
commit 6b2d844f2a
4 changed files with 7 additions and 25 deletions

View File

@ -88,7 +88,7 @@ PROGRAMS := $(TEST_CLI_PROGRAMS) $(TEST_PROGRAMS)
HEADERS := $(filter-out gen_*, $(wildcard *.h)) $(wildcard bitcoin/*.h) gen_state_names.h
CCANDIR := ccan/
CFLAGS := -g -Wall -I $(CCANDIR) -I secp256k1/include/ -DVALGRIND_HEADERS=1 $(FEATURES)
CFLAGS := -g -Wall -I $(CCANDIR) -I secp256k1/include/ $(FEATURES)
LDLIBS := -lcrypto -lprotobuf-c
$(PROGRAMS): CFLAGS+=-I.

View File

@ -1,9 +1,9 @@
#include "shadouble.h"
#include "valgrind.h"
#include <ccan/mem/mem.h>
void sha256_double(struct sha256_double *shadouble, const void *p, size_t len)
{
sha256(&shadouble->sha, check_mem(p, len), len);
sha256(&shadouble->sha, memcheck(p, len), len);
sha256(&shadouble->sha, &shadouble->sha, sizeof(shadouble->sha));
}

View File

@ -1,12 +1,12 @@
#include <ccan/crypto/sha256/sha256.h>
#include <ccan/endian/endian.h>
#include <ccan/err/err.h>
#include <ccan/mem/mem.h>
#include <ccan/read_write_all/read_write_all.h>
#include <ccan/str/hex/hex.h>
#include <ccan/tal/grab_file/grab_file.h>
#include <assert.h>
#include "tx.h"
#include "valgrind.h"
enum styles {
/* Add the CT padding stuff to amount. */
@ -197,7 +197,7 @@ static void add_tx(const struct bitcoin_tx *tx,
static void add_sha(const void *data, size_t len, void *shactx_)
{
struct sha256_ctx *ctx = shactx_;
sha256_update(ctx, check_mem(data, len), len);
sha256_update(ctx, memcheck(data, len), len);
}
void sha256_tx_for_sig(struct sha256_ctx *ctx, const struct bitcoin_tx *tx,
@ -219,7 +219,7 @@ static void add_linearize(const void *data, size_t len, void *pptr_)
size_t oldsize = tal_count(*pptr);
tal_resize(pptr, oldsize + len);
memcpy(*pptr + oldsize, check_mem(data, len), len);
memcpy(*pptr + oldsize, memcheck(data, len), len);
}
u8 *linearize_tx(const tal_t *ctx, const struct bitcoin_tx *tx)
@ -278,7 +278,7 @@ static const u8 *pull(const u8 **cursor, size_t *max, void *copy, size_t n)
*max -= n;
if (copy)
memcpy(copy, p, n);
return check_mem(p, n);
return memcheck(p, n);
}
static u64 pull_varint(const u8 **cursor, size_t *max)

View File

@ -1,18 +0,0 @@
#ifndef LIGHTNING_VALGRIND_H
#define LIGHTNING_VALGRIND_H
#ifdef VALGRIND_HEADERS
#include <valgrind/memcheck.h>
#elif !defined(VALGRIND_CHECK_MEM_IS_DEFINED)
#define VALGRIND_CHECK_MEM_IS_DEFINED(p, len)
#define RUNNING_ON_VALGRIND 0
#endif
/* Useful for hashing: makes sure we're not hashing crap *before* we use
* the hash value for something. */
static inline void *check_mem(const void *data, size_t len)
{
VALGRIND_CHECK_MEM_IS_DEFINED(data, len);
return (void *)data;
}
#endif /* LIGHTNING_VALGRIND_H */