From 8fb1814263121f5d755d9ac92b1cf1babe7c4601 Mon Sep 17 00:00:00 2001 From: Michał Łyszczek Date: Mon, 29 Jul 2019 11:37:57 +0200 Subject: src/el-decode-number.c: fix potential loose of precision on 64bit systems MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit *out |= (n[i] & 0x7f) << (i * 7); (n[i] & 0x7f) - will be an int value (32bit in most cases) and if (i * 7) is larger than 32, we will shift outside of 32bit and 0 will be written into *out which is not what we want. To prevent this, left operand of << should be first casted to 64bit and then shift should be performed. Marking no_ci since this code is not used in embedlog, and is provided as an example for decoding numbers in binary logs. no_ci Reported-by: pvs-studio Signed-off-by: Michał Łyszczek --- src/el-decode-number.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/el-decode-number.c b/src/el-decode-number.c index 7fd4c9a..f57d728 100644 --- a/src/el-decode-number.c +++ b/src/el-decode-number.c @@ -62,7 +62,11 @@ size_t el_decode_number * - set current number into right position of out */ - *out |= (n[i] & 0x7f) << (i * 7); +#ifdef LLONG_MAX + *out |= (unsigned long long)(n[i] & 0x7f) << (i * 7); +#else + *out |= (unsigned long)(n[i] & 0x7f) << (i * 7); +#endif /* we do this until number lacks of continuation bit, which means * we are done -- cgit v1.2.3-8-gadcc