Kernel: Fix comparing StringViews with strcmp().

StringView character buffer is not guaranteed to be null-terminated;
in particular it will not be null-terminated when making a substring.
This means that the buffer can not be used with C functions that expect
a null-terminated string. Instead, StringView provides a convinient
operator == for comparing it with Strings and C stirngs, so use that.

This fixes /proc/self/... resolution failures in ProcFS, since the name
("self") passed to ProcFSInode::lookup() would not be null-terminated.
This commit is contained in:
Sergey Bugaev 2019-06-12 16:25:28 +03:00 committed by Andreas Kling
parent b29a83d554
commit 75df45d709
Notes: sideshowbarker 2024-07-19 13:38:16 +09:00
2 changed files with 5 additions and 5 deletions

View file

@ -767,7 +767,7 @@ KResult Ext2FSInode::add_child(InodeIdentifier child_id, const StringView& name,
Vector<FS::DirectoryEntry> entries;
bool name_already_exists = false;
traverse_as_directory([&](auto& entry) {
if (!strcmp(entry.name, name.characters())) {
if (name == entry.name) {
name_already_exists = true;
return false;
}
@ -812,7 +812,7 @@ KResult Ext2FSInode::remove_child(const StringView& name)
Vector<FS::DirectoryEntry> entries;
traverse_as_directory([&](auto& entry) {
if (strcmp(entry.name, name.characters()) != 0)
if (name != entry.name)
entries.append(entry);
return true;
});