From d69680934e7867c11d2f06605e767e5ab4e696ed Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sun, 20 Jan 2019 16:13:35 +1030 Subject: [PATCH] short_channel_id: catch parsing errors. I upgraded my node with --disable-compat, and a heap of channels closed like: CHANNELD_NORMAL:We disagree on short_channel_ids: I have 557653x0x1351, you say 557653x2373x1", This is because the scids are strings in the databases, and it failed to parse them properly. Now we'll not start if that happens. Signed-off-by: Rusty Russell --- bitcoin/short_channel_id.h | 8 ++++---- wallet/db.h | 4 ++-- wallet/wallet.c | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/bitcoin/short_channel_id.h b/bitcoin/short_channel_id.h index 9145c2f8e..a4ec16e12 100644 --- a/bitcoin/short_channel_id.h +++ b/bitcoin/short_channel_id.h @@ -50,13 +50,13 @@ static inline u16 short_channel_id_outnum(const struct short_channel_id *scid) void mk_short_channel_id(struct short_channel_id *scid, u32 blocknum, u32 txnum, u16 outnum); -bool short_channel_id_from_str(const char *str, size_t strlen, - struct short_channel_id *dst); +bool WARN_UNUSED_RESULT short_channel_id_from_str(const char *str, size_t strlen, + struct short_channel_id *dst); char *short_channel_id_to_str(const tal_t *ctx, const struct short_channel_id *scid); -bool short_channel_id_dir_from_str(const char *str, size_t strlen, - struct short_channel_id_dir *scidd); +bool WARN_UNUSED_RESULT short_channel_id_dir_from_str(const char *str, size_t strlen, + struct short_channel_id_dir *scidd); char *short_channel_id_dir_to_str(const tal_t *ctx, const struct short_channel_id_dir *scidd); diff --git a/wallet/db.h b/wallet/db.h index 71faac6ff..2ec3b692e 100644 --- a/wallet/db.h +++ b/wallet/db.h @@ -134,8 +134,8 @@ void *sqlite3_column_arr_(const tal_t *ctx, sqlite3_stmt *stmt, int col, bool sqlite3_bind_short_channel_id(sqlite3_stmt *stmt, int col, const struct short_channel_id *id); -bool sqlite3_column_short_channel_id(sqlite3_stmt *stmt, int col, - struct short_channel_id *dest); +WARN_UNUSED_RESULT bool sqlite3_column_short_channel_id(sqlite3_stmt *stmt, int col, + struct short_channel_id *dest); bool sqlite3_bind_short_channel_id_array(sqlite3_stmt *stmt, int col, const struct short_channel_id *id); struct short_channel_id * diff --git a/wallet/wallet.c b/wallet/wallet.c index 4d506d62e..068fbb253 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -594,7 +594,8 @@ static struct channel *wallet_stmt2channel(const tal_t *ctx, struct wallet *w, s if (sqlite3_column_type(stmt, 2) != SQLITE_NULL) { scid = tal(tmpctx, struct short_channel_id); - sqlite3_column_short_channel_id(stmt, 2, scid); + if (!sqlite3_column_short_channel_id(stmt, 2, scid)) + return NULL; } else { scid = NULL; }