mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-08-13 20:48:41 +00:00
gen_rand_chars: handle errors properly
should not really happen on modern systems, but random_bytes just returns false if it fails to generate random bytes, in which case we want to die instead of returning an empty 'random' string. Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
parent
3c5bdde815
commit
a4e128a9a9
@ -1597,8 +1597,12 @@ my $gen_rand_chars = sub {
|
||||
die "invalid length $length" if $length < 1;
|
||||
|
||||
my $min = ord('!'); # first printable ascii
|
||||
my @rand_bytes = split '', Crypt::OpenSSL::Random::random_bytes($length);
|
||||
my $str = join('', map { chr((ord($_) & 0x3F) + $min) } @rand_bytes);
|
||||
|
||||
my $rand_bytes = Crypt::OpenSSL::Random::random_bytes($length);
|
||||
die "failed to generate random bytes!\n"
|
||||
if !$rand_bytes;
|
||||
|
||||
my $str = join('', map { chr((ord($_) & 0x3F) + $min) } split('', $rand_bytes));
|
||||
|
||||
return $str;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user