mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-21 14:24:09 +01:00
bitcoin/varint: fix varint reading for multibyte varints.
Embarrassing error. Reported-by: throckmorton on #lightning-dev Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
364c2cd2c0
commit
78174a09e2
1 changed files with 7 additions and 7 deletions
|
@ -39,21 +39,21 @@ size_t varint_get(const u8 *p, size_t max, varint_t *val)
|
|||
case 0xfd:
|
||||
if (max < 3)
|
||||
return 0;
|
||||
*val = ((u64)p[1] << 8) + p[0];
|
||||
*val = ((u64)p[2] << 8) + p[1];
|
||||
return 3;
|
||||
case 0xfe:
|
||||
if (max < 5)
|
||||
return 0;
|
||||
*val = ((u64)p[3] << 24) + ((u64)p[2] << 16)
|
||||
+ ((u64)p[1] << 8) + p[0];
|
||||
*val = ((u64)p[4] << 24) + ((u64)p[3] << 16)
|
||||
+ ((u64)p[2] << 8) + p[1];
|
||||
return 5;
|
||||
case 0xff:
|
||||
if (max < 9)
|
||||
return 0;
|
||||
*val = ((u64)p[7] << 56) + ((u64)p[6] << 48)
|
||||
+ ((u64)p[5] << 40) + ((u64)p[4] << 32)
|
||||
+ ((u64)p[3] << 24) + ((u64)p[2] << 16)
|
||||
+ ((u64)p[1] << 8) + p[0];
|
||||
*val = ((u64)p[8] << 56) + ((u64)p[7] << 48)
|
||||
+ ((u64)p[6] << 40) + ((u64)p[5] << 32)
|
||||
+ ((u64)p[4] << 24) + ((u64)p[3] << 16)
|
||||
+ ((u64)p[2] << 8) + p[1];
|
||||
return 9;
|
||||
default:
|
||||
*val = *p;
|
||||
|
|
Loading…
Add table
Reference in a new issue