1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 07:27:45 +00:00

LibCore: Do not try to null-terminate a ByteBuffer in read_line()

That's just silly :)
Also fix that one use of read_line() which assumes it will
null-terminated in mount.cpp (this would've blown up if the IODevice was
at EOF and had a line with the same size as max_size).
This commit is contained in:
AnotherTest 2020-11-28 18:10:03 +03:30 committed by Andreas Kling
parent c6ca8534a6
commit 129a58a2e5
2 changed files with 2 additions and 3 deletions

View file

@ -200,8 +200,7 @@ ByteBuffer IODevice::read_line(size_t max_size)
Vector<u8> new_buffered_data; Vector<u8> new_buffered_data;
new_buffered_data.append(m_buffered_data.data() + line_index, m_buffered_data.size() - line_index); new_buffered_data.append(m_buffered_data.data() + line_index, m_buffered_data.size() - line_index);
m_buffered_data = move(new_buffered_data); m_buffered_data = move(new_buffered_data);
line[line_index] = '\0'; line.trim(line_index);
line.trim(line_index + 1);
return line; return line;
} }
} }

View file

@ -96,7 +96,7 @@ static bool mount_all()
bool all_ok = true; bool all_ok = true;
while (fstab->can_read_line()) { while (fstab->can_read_line()) {
ByteBuffer buffer = fstab->read_line(1024); ByteBuffer buffer = fstab->read_line(1024);
StringView line_view = (const char*)buffer.data(); StringView line_view { buffer.data(), buffer.size() };
// Trim the trailing newline, if any. // Trim the trailing newline, if any.
if (line_view.length() > 0 && line_view[line_view.length() - 1] == '\n') if (line_view.length() > 0 && line_view[line_view.length() - 1] == '\n')