mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 17:06:31 +00:00
LibC: __generate_unique_filename(): Replace rand() with arc4random()
LibC stdlib `arc4random()` uses the `getrandom` system call which uses `KernelRng::get_good_random_bytes`. This ensures that filenames generated using functions such as `mkstemp()` are suitably randomised and are no longer predictable.
This commit is contained in:
parent
cef6b7b2e4
commit
e8e8d3caf5
|
@ -186,7 +186,7 @@ __attribute__((warn_unused_result)) int __generate_unique_filename(char* pattern
|
|||
|
||||
for (int attempt = 0; attempt < 100; ++attempt) {
|
||||
for (int i = 0; i < 6; ++i)
|
||||
pattern[start + i] = random_characters[(rand() % (sizeof(random_characters) - 1))];
|
||||
pattern[start + i] = random_characters[(arc4random() % (sizeof(random_characters) - 1))];
|
||||
struct stat st;
|
||||
int rc = lstat(pattern, &st);
|
||||
if (rc < 0 && errno == ENOENT)
|
||||
|
|
Loading…
Reference in a new issue