mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 21:58:12 +00:00
LibC+LibCore: Remove serenity_setenv()
This was called from LibCore and passed raw StringView data that may not be null terminated, then incorrectly passed those strings to getenv() and also tried printing them with just the %s format specifier.
This commit is contained in:
parent
eea4dc5bfe
commit
b16ec1880c
3 changed files with 11 additions and 15 deletions
|
@ -1430,15 +1430,17 @@ ErrorOr<void> mkfifo(StringView pathname, mode_t mode)
|
|||
|
||||
ErrorOr<void> setenv(StringView name, StringView value, bool overwrite)
|
||||
{
|
||||
#ifdef AK_OS_SERENITY
|
||||
auto const rc = ::serenity_setenv(name.characters_without_null_termination(), name.length(), value.characters_without_null_termination(), value.length(), overwrite);
|
||||
#else
|
||||
DeprecatedString name_string = name;
|
||||
DeprecatedString value_string = value;
|
||||
auto const rc = ::setenv(name_string.characters(), value_string.characters(), overwrite);
|
||||
#endif
|
||||
auto builder = TRY(StringBuilder::create());
|
||||
TRY(builder.try_append(name));
|
||||
TRY(builder.try_append('\0'));
|
||||
TRY(builder.try_append(value));
|
||||
TRY(builder.try_append('\0'));
|
||||
// Note the explicit null terminators above.
|
||||
auto c_name = builder.string_view().characters_without_null_termination();
|
||||
auto c_value = c_name + name.length() + 1;
|
||||
auto rc = ::setenv(c_name, c_value, overwrite);
|
||||
if (rc < 0)
|
||||
return Error::from_syscall("setenv"sv, -errno);
|
||||
return Error::from_errno(errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue