diff options
author | Andreas Kling <kling@serenityos.org> | 2021-06-29 22:27:11 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-29 22:28:52 +0200 |
commit | bdc905ab93e1182236507712ed4922f8105d9a3e (patch) | |
tree | 4b0e9945f5d0994e8516b6d2f1aca06062772797 /Kernel | |
parent | e2187f29563dbbdcc91e0ff6b84a9933621c0cda (diff) | |
download | serenity-bdc905ab93e1182236507712ed4922f8105d9a3e.zip |
Kernel: Make sure JSON blobs in core dumps are correctly terminated
I regressed this in 648480f715180c92c467abf8477c4eb2675107b0.
We have to make sure JsonObjectSerializer::finish() is called before
writing out the blob. This is done automatically when the serializer
is destroyed, so just wrap them in scopes.
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/CoreDump.cpp | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/Kernel/CoreDump.cpp b/Kernel/CoreDump.cpp index 4bf13071a5..b81f5b3b5a 100644 --- a/Kernel/CoreDump.cpp +++ b/Kernel/CoreDump.cpp @@ -207,21 +207,23 @@ ByteBuffer CoreDump::create_notes_process_data() const process_data.append((void*)&info, sizeof(info)); StringBuilder builder; - JsonObjectSerializer process_obj { builder }; - process_obj.add("pid"sv, m_process->pid().value()); - process_obj.add("termination_signal"sv, m_process->termination_signal()); - process_obj.add("executable_path"sv, m_process->executable() ? m_process->executable()->absolute_path() : String::empty()); - { - auto arguments_array = process_obj.add_array("arguments"sv); - for (auto& argument : m_process->arguments()) - arguments_array.add(argument); - } + JsonObjectSerializer process_obj { builder }; + process_obj.add("pid"sv, m_process->pid().value()); + process_obj.add("termination_signal"sv, m_process->termination_signal()); + process_obj.add("executable_path"sv, m_process->executable() ? m_process->executable()->absolute_path() : String::empty()); + + { + auto arguments_array = process_obj.add_array("arguments"sv); + for (auto& argument : m_process->arguments()) + arguments_array.add(argument); + } - { - auto environment_array = process_obj.add_array("environment"sv); - for (auto& variable : m_process->environment()) - environment_array.add(variable); + { + auto environment_array = process_obj.add_array("environment"sv); + for (auto& variable : m_process->environment()) + environment_array.add(variable); + } } builder.append(0); @@ -287,9 +289,11 @@ ByteBuffer CoreDump::create_notes_metadata_data() const metadata_data.append((void*)&metadata, sizeof(metadata)); StringBuilder builder; - JsonObjectSerializer metadata_obj { builder }; - for (auto& it : m_process->coredump_metadata()) - metadata_obj.add(it.key, it.value); + { + JsonObjectSerializer metadata_obj { builder }; + for (auto& it : m_process->coredump_metadata()) + metadata_obj.add(it.key, it.value); + } builder.append(0); metadata_data.append(builder.string_view().characters_without_null_termination(), builder.length()); |