mirror of
https://github.com/lcn2/calc.git
synced 2025-08-19 01:13:27 +03:00
Added paranoia size limited code for seed() builtin.
Just to be padanticly sure, we prevent seed() from ever returning a value >= 2^64.
This commit is contained in:
12
seed.c
12
seed.c
@@ -716,6 +716,18 @@ pseudo_seed(void)
|
|||||||
memset(hash.v, 0, hash.len*sizeof(HALF)); /* paranoia */
|
memset(hash.v, 0, hash.len*sizeof(HALF)); /* paranoia */
|
||||||
hash.sign = 0;
|
hash.sign = 0;
|
||||||
memcpy((void *)hash.v, (void *)&hash_val, sizeof(hash_val));
|
memcpy((void *)hash.v, (void *)&hash_val, sizeof(hash_val));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Force the hash as ZVALUE to be at most, 64 bits long.
|
||||||
|
* It is almost certainly the case that the hash as ZVALUE
|
||||||
|
* is at most 64 bits in length: this code guarantees it.
|
||||||
|
*
|
||||||
|
* BTW: One can safely assume that 64 is an integer multiple of BASEB:
|
||||||
|
* likely 4, 2, or 1 times BASEB.
|
||||||
|
*/
|
||||||
|
if (hash.len > 64/BASEB) {
|
||||||
|
hash.len = 64/BASEB;
|
||||||
|
}
|
||||||
ztrim(&hash);
|
ztrim(&hash);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user