mirror of
https://github.com/SerenityOS/serenity
synced 2026-04-25 17:15:42 +02:00
LibCore: Make get_salt() fallible so we get an error instead of crashing
This commit is contained in:
committed by
Nico Weber
parent
61ebfdab56
commit
2f3ad5ca28
@@ -27,7 +27,7 @@
|
||||
|
||||
namespace Core {
|
||||
|
||||
static ByteString get_salt()
|
||||
static ErrorOr<ByteString> get_salt()
|
||||
{
|
||||
char random_data[12];
|
||||
fill_with_random({ random_data, sizeof(random_data) });
|
||||
@@ -35,8 +35,7 @@ static ByteString get_salt()
|
||||
StringBuilder builder;
|
||||
builder.append("$5$"sv);
|
||||
|
||||
// FIXME: change to TRY() and make method fallible
|
||||
auto salt_string = MUST(encode_base64({ random_data, sizeof(random_data) }));
|
||||
auto salt_string = TRY(encode_base64({ random_data, sizeof(random_data) }));
|
||||
builder.append(salt_string);
|
||||
|
||||
return builder.to_byte_string();
|
||||
@@ -184,9 +183,10 @@ ErrorOr<void> Account::login() const
|
||||
return {};
|
||||
}
|
||||
|
||||
void Account::set_password(SecretString const& password)
|
||||
ErrorOr<void> Account::set_password(SecretString const& password)
|
||||
{
|
||||
m_password_hash = crypt(password.characters(), get_salt().characters());
|
||||
m_password_hash = crypt(password.characters(), TRY(get_salt()).characters());
|
||||
return {};
|
||||
}
|
||||
|
||||
void Account::set_password_enabled(bool enabled)
|
||||
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
|
||||
// Setters only affect in-memory copy of password.
|
||||
// You must call sync to apply changes.
|
||||
void set_password(SecretString const& password);
|
||||
ErrorOr<void> set_password(SecretString const& password);
|
||||
void set_password_enabled(bool enabled);
|
||||
void set_home_directory(StringView home_directory) { m_home_directory = home_directory; }
|
||||
void set_uid(uid_t uid) { m_uid = uid; }
|
||||
|
||||
@@ -87,7 +87,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
return 1;
|
||||
}
|
||||
|
||||
target_account.set_password(new_password);
|
||||
TRY(target_account.set_password(new_password));
|
||||
}
|
||||
|
||||
TRY(Core::System::pledge("stdio wpath rpath cpath fattr"));
|
||||
|
||||
Reference in New Issue
Block a user