From 78174a09e244d7f912b7bcdc3cc9463191f6f017 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 7 Jul 2016 11:55:32 +0930 Subject: [PATCH] bitcoin/varint: fix varint reading for multibyte varints. Embarrassing error. Reported-by: throckmorton on #lightning-dev Signed-off-by: Rusty Russell --- bitcoin/varint.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bitcoin/varint.c b/bitcoin/varint.c index e041f422e..1e97cddd3 100644 --- a/bitcoin/varint.c +++ b/bitcoin/varint.c @@ -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;