encrypt_pw: check return value matches expected format

since this manually constructs the input string for `crypt`, which looks
different depending on used prefix/hashing algorithm, ensure that it was
understood by crypt and that it returned a proper hashed password line.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2025-03-31 12:03:34 +02:00 committed by Thomas Lamprecht
parent 6cbbb1863d
commit d9e544ff71

View File

@ -1824,7 +1824,12 @@ sub encrypt_pw {
die "Cannot hash password, unknown crypt prefix '$prefix'\n";
}
return crypt(encode("utf8", $pw), $input);
my $res = crypt(encode("utf8", $pw), $input);
if ($res =~ m/^\$$prefix\$/) {
return $res;
} else {
die "Failed to hash password!\n";
}
}
# intended usage: convert_size($val, "kb" => "gb")