Skip to content

Commit

Permalink
bitcoin/varint: fix varint reading for multibyte varints.
Browse files Browse the repository at this point in the history
Embarrassing error.

Reported-by: throckmorton on #lightning-dev
Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Jul 7, 2016
1 parent 364c2cd commit 78174a0
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions bitcoin/varint.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 78174a0

Please sign in to comment.