mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-05 06:32:30 +02:00
LibCore: Make get_password return SecretString instead of String
We shouldn't let secrets sit around in memory, as they could potentially be retrieved by an attacker, or left in memory during a core dump.
This commit is contained in:
committed by
Andreas Kling
parent
3bf6902790
commit
9e667453c7
Notes:
sideshowbarker
2024-07-18 04:08:21 +09:00
Author: https://github.com/bgianfo Commit: https://github.com/SerenityOS/serenity/commit/9e667453c7e Pull-request: https://github.com/SerenityOS/serenity/pull/9972 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/petelliott
@@ -13,7 +13,7 @@
|
||||
|
||||
namespace Core {
|
||||
|
||||
Result<String, OSError> get_password(const StringView& prompt)
|
||||
Result<SecretString, OSError> get_password(const StringView& prompt)
|
||||
{
|
||||
if (write(STDOUT_FILENO, prompt.characters_without_null_termination(), prompt.length()) < 0)
|
||||
return OSError(errno);
|
||||
@@ -44,8 +44,6 @@ Result<String, OSError> get_password(const StringView& prompt)
|
||||
// Remove trailing '\n' read by getline().
|
||||
password[line_length - 1] = '\0';
|
||||
|
||||
String s(password);
|
||||
free(password);
|
||||
return s;
|
||||
return SecretString::take_ownership(password, line_length);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user