LibCrypto: Remove all uses of VLAs

This removes all uses of VLAs with either Vectors with inline capacity
for the expected soft upper bound, or the occasional heap allocation.
This commit is contained in:
Ali Mohammad Pur 2021-05-13 12:13:11 +04:30 committed by Andreas Kling
commit b05beb79d4
Notes: sideshowbarker 2024-07-18 18:14:19 +09:00
7 changed files with 41 additions and 36 deletions

View file

@ -273,9 +273,10 @@ UnsignedBigInteger random_number(const UnsignedBigInteger& min, const UnsignedBi
UnsignedBigInteger base;
auto size = range.trimmed_length() * sizeof(u32) + 2;
// "+2" is intentional (see below).
// Also, if we're about to crash anyway, at least produce a nice error:
VERIFY(size < 8 * MiB);
u8 buf[size];
ByteBuffer buffer;
buffer.grow(size);
auto* buf = buffer.data();
fill_with_random(buf, size);
UnsignedBigInteger random { buf, size };
// At this point, `random` is a large number, in the range [0, 256^size).