mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
chaintopology: Protect against underflow when computing first_blocknum.
Fixes: #1423 (Hopefully) Reported-by: @NicolasDorier
This commit is contained in:
parent
aa71a822b3
commit
d5a67ec87a
@ -525,10 +525,20 @@ static void get_init_blockhash(struct bitcoind *bitcoind, u32 blockcount,
|
||||
if (blockcount < topo->first_blocknum) {
|
||||
if (bitcoind->ld->config.rescan < 0) {
|
||||
/* Absolute blockheight, but bitcoind's blockheight isn't there yet */
|
||||
topo->first_blocknum = blockcount - 1;
|
||||
/* Protect against underflow in subtraction.
|
||||
* Possible in regtest mode. */
|
||||
if (blockcount < 1)
|
||||
topo->first_blocknum = 0;
|
||||
else
|
||||
topo->first_blocknum = blockcount - 1;
|
||||
} else if (topo->first_blocknum == UINT32_MAX) {
|
||||
/* Relative rescan, but we didn't know the blockheight */
|
||||
topo->first_blocknum = blockcount - bitcoind->ld->config.rescan;
|
||||
/* Protect against underflow in subtraction.
|
||||
* Possible in regtest mode. */
|
||||
if (blockcount < bitcoind->ld->config.rescan)
|
||||
topo->first_blocknum = 0;
|
||||
else
|
||||
topo->first_blocknum = blockcount - bitcoind->ld->config.rescan;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user