mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:27:45 +00:00
AK: Replace the mutable String::replace API with an immutable version
This removes the awkward String::replace API which was the only String API which mutated the String and replaces it with a new immutable version that returns a new String with the replacements applied. This also fixes a couple of UAFs that were caused by the use of this API. As an optimization an equivalent StringView::replace API was also added to remove an unnecessary String allocations in the format of: `String { view }.replace(...);`
This commit is contained in:
parent
aba4c9579f
commit
6704961c82
26 changed files with 72 additions and 118 deletions
|
@ -425,9 +425,7 @@ void endservent()
|
|||
static bool fill_getserv_buffers(const char* line, ssize_t read)
|
||||
{
|
||||
// Splitting the line by tab delimiter and filling the servent buffers name, port, and protocol members.
|
||||
String string_line = String(line, read);
|
||||
string_line.replace(" ", "\t", true);
|
||||
auto split_line = string_line.split('\t');
|
||||
auto split_line = StringView(line, read).replace(" ", "\t", true).split('\t');
|
||||
|
||||
// This indicates an incorrect file format.
|
||||
// Services file entries should always at least contain
|
||||
|
@ -450,11 +448,7 @@ static bool fill_getserv_buffers(const char* line, ssize_t read)
|
|||
__getserv_port_buffer = number.value();
|
||||
|
||||
// Remove any annoying whitespace at the end of the protocol.
|
||||
port_protocol_split[1].replace(" ", "", true);
|
||||
port_protocol_split[1].replace("\t", "", true);
|
||||
port_protocol_split[1].replace("\n", "", true);
|
||||
|
||||
__getserv_protocol_buffer = port_protocol_split[1];
|
||||
__getserv_protocol_buffer = port_protocol_split[1].replace(" ", "", true).replace("\t", "", true).replace("\n", "", true);
|
||||
__getserv_alias_list_buffer.clear();
|
||||
|
||||
// If there are aliases for the service, we will fill the alias list buffer.
|
||||
|
@ -610,8 +604,7 @@ void endprotoent()
|
|||
static bool fill_getproto_buffers(const char* line, ssize_t read)
|
||||
{
|
||||
String string_line = String(line, read);
|
||||
string_line.replace(" ", "\t", true);
|
||||
auto split_line = string_line.split('\t');
|
||||
auto split_line = string_line.replace(" ", "\t", true).split('\t');
|
||||
|
||||
// This indicates an incorrect file format. Protocols file entries should
|
||||
// always have at least a name and a protocol.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue