Kernel: Harden DevPtsFSInode::traverse_as_directory against OOM

Use the try variants of AK::StringBuilder append APIs to harden this
function against OOM.
This commit is contained in:
Brian Gianforcaro 2022-01-09 02:59:20 -08:00 committed by Andreas Kling
parent 787bfcc530
commit f8ad3cc6a0
Notes: sideshowbarker 2024-07-17 21:07:44 +09:00

View file

@ -114,9 +114,10 @@ ErrorOr<void> DevPtsFSInode::traverse_as_directory(Function<ErrorOr<void>(FileSy
TRY(callback({ "..", identifier(), 0 }));
return SlavePTY::all_instances().with([&](auto& list) -> ErrorOr<void> {
StringBuilder builder;
for (SlavePTY& slave_pty : list) {
StringBuilder builder;
builder.appendff("{}", slave_pty.index());
builder.clear();
TRY(builder.try_appendff("{}", slave_pty.index()));
TRY(callback({ builder.string_view(), { fsid(), pty_index_to_inode_index(slave_pty.index()) }, 0 }));
}
return {};