mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:38:10 +00:00
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:
parent
b29a83d554
commit
75df45d709
2 changed files with 5 additions and 5 deletions
|
@ -767,7 +767,7 @@ KResult Ext2FSInode::add_child(InodeIdentifier child_id, const StringView& name,
|
||||||
Vector<FS::DirectoryEntry> entries;
|
Vector<FS::DirectoryEntry> entries;
|
||||||
bool name_already_exists = false;
|
bool name_already_exists = false;
|
||||||
traverse_as_directory([&](auto& entry) {
|
traverse_as_directory([&](auto& entry) {
|
||||||
if (!strcmp(entry.name, name.characters())) {
|
if (name == entry.name) {
|
||||||
name_already_exists = true;
|
name_already_exists = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -812,7 +812,7 @@ KResult Ext2FSInode::remove_child(const StringView& name)
|
||||||
|
|
||||||
Vector<FS::DirectoryEntry> entries;
|
Vector<FS::DirectoryEntry> entries;
|
||||||
traverse_as_directory([&](auto& entry) {
|
traverse_as_directory([&](auto& entry) {
|
||||||
if (strcmp(entry.name, name.characters()) != 0)
|
if (name != entry.name)
|
||||||
entries.append(entry);
|
entries.append(entry);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
|
@ -966,7 +966,7 @@ InodeIdentifier ProcFSInode::lookup(StringView name)
|
||||||
if (entry.name == nullptr)
|
if (entry.name == nullptr)
|
||||||
continue;
|
continue;
|
||||||
if (entry.proc_file_type > __FI_Root_Start && entry.proc_file_type < __FI_Root_End) {
|
if (entry.proc_file_type > __FI_Root_Start && entry.proc_file_type < __FI_Root_End) {
|
||||||
if (!strcmp(entry.name, name.characters())) {
|
if (name == entry.name) {
|
||||||
return to_identifier(fsid(), PDI_Root, 0, (ProcFileType)entry.proc_file_type);
|
return to_identifier(fsid(), PDI_Root, 0, (ProcFileType)entry.proc_file_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -988,7 +988,7 @@ InodeIdentifier ProcFSInode::lookup(StringView name)
|
||||||
if (proc_file_type == FI_Root_sys) {
|
if (proc_file_type == FI_Root_sys) {
|
||||||
for (int i = 0; i < fs().m_sys_entries.size(); ++i) {
|
for (int i = 0; i < fs().m_sys_entries.size(); ++i) {
|
||||||
auto& entry = fs().m_sys_entries[i];
|
auto& entry = fs().m_sys_entries[i];
|
||||||
if (!strcmp(entry.name, name.characters()))
|
if (name == entry.name)
|
||||||
return sys_var_to_identifier(fsid(), i);
|
return sys_var_to_identifier(fsid(), i);
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
|
@ -1005,7 +1005,7 @@ InodeIdentifier ProcFSInode::lookup(StringView name)
|
||||||
continue;
|
continue;
|
||||||
if (entry.name == nullptr)
|
if (entry.name == nullptr)
|
||||||
continue;
|
continue;
|
||||||
if (!strcmp(entry.name, name.characters())) {
|
if (name == entry.name) {
|
||||||
return to_identifier(fsid(), PDI_PID, to_pid(identifier()), (ProcFileType)entry.proc_file_type);
|
return to_identifier(fsid(), PDI_PID, to_pid(identifier()), (ProcFileType)entry.proc_file_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue