-
Notifications
You must be signed in to change notification settings - Fork 137
Fix: Check flatbuffer integrity before parsing #1864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,6 +14,9 @@ | |||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| #include "remote_config/src/desktop/metadata.h" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| #include <cerrno> | ||||||||||||||||||||||||||||||||||||||||
| #include <cstdlib> | ||||||||||||||||||||||||||||||||||||||||
| #include <limits> | ||||||||||||||||||||||||||||||||||||||||
| #include <map> | ||||||||||||||||||||||||||||||||||||||||
| #include <string> | ||||||||||||||||||||||||||||||||||||||||
|
AustinBenoit marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
@@ -58,6 +61,9 @@ std::string RemoteConfigMetadata::Serialize() const { | |||||||||||||||||||||||||||||||||||||||
| void RemoteConfigMetadata::Deserialize(const std::string& buffer) { | ||||||||||||||||||||||||||||||||||||||||
| const uint8_t* data = reinterpret_cast<const uint8_t*>(buffer.data()); | ||||||||||||||||||||||||||||||||||||||||
| size_t size = buffer.size(); | ||||||||||||||||||||||||||||||||||||||||
| if (!flexbuffers::VerifyBuffer(data, size)) { | ||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| auto struct_map = flexbuffers::GetRoot(data, size).AsMap(); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| flexbuffers::Map info = struct_map["info"].AsMap(); | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -75,7 +81,18 @@ void RemoteConfigMetadata::Deserialize(const std::string& buffer) { | |||||||||||||||||||||||||||||||||||||||
| settings_.clear(); | ||||||||||||||||||||||||||||||||||||||||
| flexbuffers::Map settings = struct_map["settings"].AsMap(); | ||||||||||||||||||||||||||||||||||||||||
| for (int i = 0, n = settings.size(); i < n; ++i) { | ||||||||||||||||||||||||||||||||||||||||
| int int_key = std::stoi(settings.Keys()[i].AsKey()); | ||||||||||||||||||||||||||||||||||||||||
| const char* key_str = settings.Keys()[i].AsKey(); | ||||||||||||||||||||||||||||||||||||||||
| if (!key_str) continue; | ||||||||||||||||||||||||||||||||||||||||
| char* endptr = nullptr; | ||||||||||||||||||||||||||||||||||||||||
| long raw_key = std::strtol(key_str, &endptr, 10); | ||||||||||||||||||||||||||||||||||||||||
| if (endptr == key_str || *endptr != '\0') { | ||||||||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| if (raw_key < std::numeric_limits<int>::min() || | ||||||||||||||||||||||||||||||||||||||||
| raw_key > std::numeric_limits<int>::max()) { | ||||||||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+86
to
+94
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On platforms where To correctly detect overflow on all platforms, you should clear
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
| int int_key = static_cast<int>(raw_key); | ||||||||||||||||||||||||||||||||||||||||
| settings_[static_cast<ConfigSetting>(int_key)] = | ||||||||||||||||||||||||||||||||||||||||
| settings.Values()[i].AsString().c_str(); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
app.options().package_name()returnsnullptr, constructing astd::stringdirectly from it will result in undefined behavior (typically a crash). It is safer to perform a null check before constructing the string.