mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 15:44:21 +01:00
Add assertions in various places to ensure tal_fmt doesn't receive NULL as argument for strings.
This commit is contained in:
committed by
Christian Decker
parent
aba3d5f34d
commit
b857b2e843
@@ -5,6 +5,7 @@
|
||||
#include <common/type_to_string.h>
|
||||
#include <common/utils.h>
|
||||
#include <inttypes.h>
|
||||
#include <assert.h>
|
||||
|
||||
/* We need at least one, and these are in CCAN so register it here. */
|
||||
REGISTER_TYPE_TO_HEXSTR(sha256);
|
||||
@@ -20,6 +21,8 @@ char *type_to_string_(const tal_t *ctx, const char *typename,
|
||||
static size_t num_p;
|
||||
static struct type_to_string **t = NULL;
|
||||
|
||||
assert(typename != NULL);
|
||||
|
||||
if (!t)
|
||||
t = autodata_get(type_to_string, &num_p);
|
||||
|
||||
|
||||
@@ -53,6 +53,9 @@ const char *tmpctx_any(void)
|
||||
struct tmpctx *t = list_top(&tmpctxs, struct tmpctx, list);
|
||||
|
||||
if (t)
|
||||
{
|
||||
assert(t->file != NULL);
|
||||
return tal_fmt(t, "%s:%u", t->file, t->line);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -264,6 +264,7 @@ static void connection_complete_ok(struct json_connection *jcon,
|
||||
const struct json_result *result)
|
||||
{
|
||||
assert(id != NULL);
|
||||
assert(result != NULL);
|
||||
|
||||
/* This JSON is simple enough that we build manually */
|
||||
json_done(jcon, cmd, take(tal_fmt(jcon,
|
||||
|
||||
@@ -73,6 +73,8 @@ static int json_add_syminfo(void *data, uintptr_t pc UNUSED,
|
||||
struct json_result *response = data;
|
||||
char *str;
|
||||
|
||||
assert(filename != NULL);
|
||||
assert(function != NULL);
|
||||
str = tal_fmt(response, "%s:%u (%s)", filename, lineno, function);
|
||||
json_add_string(response, NULL, str);
|
||||
tal_free(str);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
static bool match(const char *str, const char *abbrev, const char *full)
|
||||
{
|
||||
@@ -26,6 +27,8 @@ char *opt_set_time(const char *arg, struct timerel *t)
|
||||
char *endp;
|
||||
unsigned long int l;
|
||||
|
||||
assert(arg != NULL);
|
||||
|
||||
/* This is how the manpage says to do it. Yech. */
|
||||
errno = 0;
|
||||
l = strtol(arg, &endp, 0);
|
||||
@@ -82,6 +85,8 @@ char *opt_set_timeabs(const char *arg, struct timeabs *t)
|
||||
{
|
||||
long double d;
|
||||
|
||||
assert(arg != NULL);
|
||||
|
||||
if (sscanf(arg, "%Lf", &d) != 1)
|
||||
return tal_fmt(NULL, "'%s' is not a time", arg);
|
||||
t->ts.tv_sec = d;
|
||||
|
||||
@@ -71,6 +71,8 @@ static char *opt_set_u32(const char *arg, u32 *u)
|
||||
char *endp;
|
||||
unsigned long l;
|
||||
|
||||
assert(arg != NULL);
|
||||
|
||||
/* This is how the manpage says to do it. Yech. */
|
||||
errno = 0;
|
||||
l = strtoul(arg, &endp, 0);
|
||||
@@ -87,6 +89,8 @@ static char *opt_set_u16(const char *arg, u16 *u)
|
||||
char *endp;
|
||||
unsigned long l;
|
||||
|
||||
assert(arg != NULL);
|
||||
|
||||
/* This is how the manpage says to do it. Yech. */
|
||||
errno = 0;
|
||||
l = strtoul(arg, &endp, 0);
|
||||
@@ -103,6 +107,8 @@ static char *opt_set_s32(const char *arg, s32 *u)
|
||||
char *endp;
|
||||
long l;
|
||||
|
||||
assert(arg != NULL);
|
||||
|
||||
/* This is how the manpage says to do it. Yech. */
|
||||
errno = 0;
|
||||
l = strtol(arg, &endp, 0);
|
||||
@@ -119,6 +125,8 @@ static char *opt_add_ipaddr(const char *arg, struct lightningd *ld)
|
||||
size_t n = tal_count(ld->wireaddrs);
|
||||
char const *err_msg;
|
||||
|
||||
assert(arg != NULL);
|
||||
|
||||
tal_resize(&ld->wireaddrs, n+1);
|
||||
|
||||
if (!parse_wireaddr(arg, &ld->wireaddrs[n], ld->portnum, &err_msg)) {
|
||||
@@ -146,6 +154,8 @@ static void opt_show_u16(char buf[OPT_SHOW_LEN], const u16 *u)
|
||||
|
||||
static char *opt_set_network(const char *arg, struct lightningd *ld)
|
||||
{
|
||||
assert(arg != NULL);
|
||||
|
||||
ld->topology->bitcoind->chainparams = chainparams_for_network(arg);
|
||||
if (!ld->topology->bitcoind->chainparams)
|
||||
return tal_fmt(NULL, "Unknown network name '%s'", arg);
|
||||
@@ -160,6 +170,8 @@ static void opt_show_network(char buf[OPT_SHOW_LEN],
|
||||
|
||||
static char *opt_set_rgb(const char *arg, struct lightningd *ld)
|
||||
{
|
||||
assert(arg != NULL);
|
||||
|
||||
ld->rgb = tal_free(ld->rgb);
|
||||
/* BOLT #7:
|
||||
*
|
||||
@@ -173,6 +185,8 @@ static char *opt_set_rgb(const char *arg, struct lightningd *ld)
|
||||
|
||||
static char *opt_set_alias(const char *arg, struct lightningd *ld)
|
||||
{
|
||||
assert(arg != NULL);
|
||||
|
||||
ld->alias = tal_free(ld->alias);
|
||||
/* BOLT #7:
|
||||
*
|
||||
@@ -298,6 +312,8 @@ static void config_register_opts(struct lightningd *ld)
|
||||
#if DEVELOPER
|
||||
static char *opt_set_hsm_seed(const char *arg, struct lightningd *ld)
|
||||
{
|
||||
assert(arg != NULL);
|
||||
|
||||
ld->dev_hsm_seed = tal_hexdata(ld, arg, strlen(arg));
|
||||
if (ld->dev_hsm_seed)
|
||||
return NULL;
|
||||
@@ -479,6 +495,7 @@ static void config_log_stderr_exit(const char *fmt, ...)
|
||||
const char *arg = va_arg(ap, const char *);
|
||||
const char *problem = va_arg(ap, const char *);
|
||||
|
||||
assert(arg != NULL);
|
||||
msg = tal_fmt(NULL, "%s line %s: %.*s: %s",
|
||||
argv0, arg+strlen(arg)+1, len-2, arg+2, problem);
|
||||
} else {
|
||||
|
||||
@@ -672,6 +672,7 @@ static void json_sendpay_on_resolve(const struct sendpay_result *r,
|
||||
r->onionreply, tal_len(r->onionreply));
|
||||
json_object_end(data);
|
||||
|
||||
assert(r->details != NULL);
|
||||
msg = tal_fmt(cmd,
|
||||
"failed: WIRE_PERMANENT_NODE_FAILURE "
|
||||
"(%s)",
|
||||
@@ -700,6 +701,7 @@ static void json_sendpay_on_resolve(const struct sendpay_result *r,
|
||||
tal_len(fail->channel_update));
|
||||
json_object_end(data);
|
||||
|
||||
assert(r->details != NULL);
|
||||
msg = tal_fmt(cmd,
|
||||
"failed: %s (%s)",
|
||||
onion_type_name(fail->failcode),
|
||||
|
||||
@@ -106,6 +106,7 @@ static void json_pay_failure(struct pay *pay,
|
||||
tal_len(fail->channel_update));
|
||||
json_object_end(data);
|
||||
|
||||
assert(r->details != NULL);
|
||||
msg = tal_fmt(pay,
|
||||
"failed: %s (%s)",
|
||||
onion_type_name(fail->failcode),
|
||||
|
||||
@@ -805,6 +805,7 @@ void onchain_failed_our_htlc(const struct channel *channel,
|
||||
hout->failcode = WIRE_PERMANENT_CHANNEL_FAILURE;
|
||||
|
||||
if (!hout->in) {
|
||||
assert(why != NULL);
|
||||
char *localfail = tal_fmt(channel, "%s: %s",
|
||||
onion_type_name(WIRE_PERMANENT_CHANNEL_FAILURE),
|
||||
why);
|
||||
|
||||
@@ -659,6 +659,8 @@ static struct subd *new_subd(struct lightningd *ld,
|
||||
const char *debug_subd = NULL;
|
||||
int disconnect_fd = -1;
|
||||
|
||||
assert(name != NULL);
|
||||
|
||||
#if DEVELOPER
|
||||
debug_subd = ld->dev_debug_subdaemon;
|
||||
disconnect_fd = ld->dev_disconnect_fd;
|
||||
|
||||
@@ -489,6 +489,7 @@ static unsigned int htlc_id_from_pkt(const Pkt *pkt)
|
||||
static Pkt *htlc_pkt(const tal_t *ctx, const char *prefix, unsigned int id)
|
||||
{
|
||||
assert(id != -1);
|
||||
assert(prefix != NULL);
|
||||
return (Pkt *)tal_fmt(ctx, "%s: HTLC #%u", prefix, id);
|
||||
}
|
||||
|
||||
@@ -501,6 +502,7 @@ static unsigned int htlc_id_from_tx(const struct bitcoin_tx *tx)
|
||||
static struct bitcoin_tx *htlc_tx(const tal_t *ctx,
|
||||
const char *prefix, unsigned int id)
|
||||
{
|
||||
assert(prefix != NULL);
|
||||
return (struct bitcoin_tx *)tal_fmt(ctx, "%s HTLC #%u", prefix, id);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user