upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBitflash <admin@bitflash.network>2026-08-07 16:46:15 -0300
committerBitflash <admin@bitflash.network>2026-08-07 16:46:15 -0300
commit060a37de4a1f08ffb5939c8fc47a805c5d0d0024 (patch)
tree11742f480ae54265d3817bc720213f985587f9bf /src
parent78cf0c3cb6752bd36bbc8fe7017d5d60cca13da7 (diff)
bignum: shift setint64 in unsigned space to avoid signed overflow UB
setint64() extracted big-endian bytes with a signed left shift (n <<= 8). When the top byte is set that overflows int64 -- undefined behaviour, which the script fuzzer flagged under UBSan (bignum.h:158). The result was correct on two's-complement hardware, so this is a latent UB inherited from the original 0.1 code, not a behaviour change. Do the shift on a uint64.
Diffstat (limited to 'src')
-rw-r--r--src/bignum.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/bignum.h b/src/bignum.h
index 9da104b..6a295b2 100644
--- a/src/bignum.h
+++ b/src/bignum.h
@@ -155,7 +155,9 @@ public:
155 for (int i = 0; i < 8; i++) 155 for (int i = 0; i < 8; i++)
156 { 156 {
157 unsigned char c = (n >> 56) & 0xff; 157 unsigned char c = (n >> 56) & 0xff;
158 n <<= 8; 158 n = (int64)((uint64)n << 8); // shift in unsigned space; <<= on a
159 // signed int64 with the top byte set
160 // is overflow UB (fuzzer/UBSan finding)
159 if (fLeadingZeroes) 161 if (fLeadingZeroes)
160 { 162 {
161 if (c == 0) 163 if (c == 0)