mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 18:35:46 +02:00
fix: buffer overrun in GetRandomHex (#4717)
This commit is contained in:
parent
94d9cf79ef
commit
df88b9e1f8
1 changed files with 5 additions and 3 deletions
|
@ -88,16 +88,18 @@ static string GetRandomHex(size_t len) {
|
|||
std::string res(len, '\0');
|
||||
size_t indx = 0;
|
||||
|
||||
for (; indx < len; indx += 16) { // 2 chars per byte
|
||||
for (; indx + 16 <= len; indx += 16) { // 2 chars per byte
|
||||
absl::numbers_internal::FastHexToBufferZeroPad16(bit_gen(), res.data() + indx);
|
||||
}
|
||||
|
||||
DCHECK_LE(indx, len);
|
||||
|
||||
if (indx < len) {
|
||||
char buf[24];
|
||||
absl::numbers_internal::FastHexToBufferZeroPad16(bit_gen(), buf);
|
||||
|
||||
for (unsigned j = 0; indx < len; indx++, j++) {
|
||||
res[indx] = buf[j];
|
||||
for (unsigned j = 0; indx < len;) {
|
||||
res[indx++] = buf[j++];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue