Skip to content

Commit b1f578c

Browse files
Rename rapidjson helper functions
1 parent 65f0139 commit b1f578c

File tree

7 files changed

+20
-14
lines changed

7 files changed

+20
-14
lines changed

src/native/corehost/comhost/clsidmap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ namespace
100100
throw HResultException{ E_UNEXPECTED }; // This should never happen in Windows 7+
101101

102102
json_parser_t json;
103-
if (!json.parse_raw_data(reinterpret_cast<char*>(data), size, _X("<embedded .clsidmap>")))
103+
if (!json.parse_fully_trusted_raw_data(reinterpret_cast<char*>(data), size, _X("<embedded .clsidmap>")))
104104
{
105105
trace::error(_X("Embedded .clsidmap format is invalid"));
106106
throw HResultException{ StatusCode::InvalidConfigFile };
@@ -178,7 +178,7 @@ namespace
178178
return {};
179179

180180
json_parser_t json;
181-
if (!json.parse_file(map_file_name))
181+
if (!json.parse_fully_trusted_file(map_file_name))
182182
{
183183
trace::error(_X("File .clsidmap format is invalid"));
184184
throw HResultException{ StatusCode::InvalidConfigFile };

src/native/corehost/fxr/sdk_resolver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ bool sdk_resolver::parse_global_file(pal::string_t global_file_path)
325325
// After we're done parsing `global_file_path`, none of its contents will be referenced
326326
// from the data private to json_parser_t; it's safe to declare it on the stack.
327327
json_parser_t json;
328-
if (!json.parse_file(global_file_path))
328+
if (!json.parse_fully_trusted_file(global_file_path))
329329
{
330330
return false;
331331
}

src/native/corehost/fxr/standalone/hostpolicy_resolver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace
2929

3030
pal::string_t retval;
3131
json_parser_t json;
32-
if (!json.parse_file(deps_json))
32+
if (!json.parse_fully_trusted_file(deps_json))
3333
{
3434
return retval;
3535
}

src/native/corehost/hostpolicy/deps_format.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ deps_json_t::rid_fallback_graph_t deps_json_t::get_rid_fallback_graph(const pal:
9494
return rid_fallback_graph;
9595

9696
json_parser_t json;
97-
if (!json.parse_file(deps_path_local))
97+
if (!json.parse_fully_trusted_file(deps_path_local))
9898
return rid_fallback_graph;
9999

100100
populate_rid_fallback_graph(json.document(), rid_fallback_graph);
@@ -586,7 +586,7 @@ void deps_json_t::load(bool is_framework_dependent, std::function<void(const jso
586586
}
587587

588588
json_parser_t json;
589-
if (!json.parse_file(m_deps_file))
589+
if (!json.parse_fully_trusted_file(m_deps_file))
590590
return;
591591

592592
m_valid = true;

src/native/corehost/json_parser.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ void get_line_column_from_offset(const char* data, uint64_t size, size_t offset,
4444

4545
} // empty namespace
4646

47-
bool json_parser_t::parse_raw_data(char* data, int64_t size, const pal::string_t& context)
47+
bool json_parser_t::parse_fully_trusted_raw_data(char* data, int64_t size, const pal::string_t& context)
4848
{
49+
// This code assumes that the provided data is fully trusted; that is, that no portion
50+
// of it has been provided by a hostile agent.
51+
4952
assert(data != nullptr);
5053

5154
constexpr auto flags = rapidjson::ParseFlag::kParseStopWhenDoneFlag | rapidjson::ParseFlag::kParseCommentsFlag;
@@ -81,10 +84,13 @@ bool json_parser_t::parse_raw_data(char* data, int64_t size, const pal::string_t
8184
return true;
8285
}
8386

84-
bool json_parser_t::parse_file(const pal::string_t& path)
87+
bool json_parser_t::parse_fully_trusted_file(const pal::string_t& path)
8588
{
8689
// This code assumes that the caller has checked that the file `path` exists
87-
// either within the bundle, or as a real file on disk.
90+
// either within the bundle, or as a real file on disk. It also assumes
91+
// that the contents of the target file are fully trusted; that is, that no
92+
// portion of its contents has been provided by a hostile agent.
93+
8894
assert(m_data == nullptr);
8995
assert(m_bundle_location == nullptr);
9096

@@ -129,7 +135,7 @@ bool json_parser_t::parse_file(const pal::string_t& path)
129135
data += 3;
130136
}
131137

132-
return parse_raw_data(data, size, path);
138+
return parse_fully_trusted_raw_data(data, size, path);
133139
}
134140

135141
json_parser_t::~json_parser_t()

src/native/corehost/json_parser.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class json_parser_t {
3636

3737
const document_t& document() const { return m_document; }
3838

39-
bool parse_raw_data(char* data, int64_t size, const pal::string_t& context);
40-
bool parse_file(const pal::string_t& path);
39+
bool parse_fully_trusted_raw_data(char* data, int64_t size, const pal::string_t& context);
40+
bool parse_fully_trusted_file(const pal::string_t& path);
4141

4242
json_parser_t()
4343
: m_data(nullptr)

src/native/corehost/runtime_config.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ bool runtime_config_t::ensure_dev_config_parsed()
343343
// runtimeconfig.dev.json is never bundled into the single-file app.
344344
// So, only a file on disk is processed.
345345
json_parser_t json;
346-
if (!json.parse_file(m_dev_path))
346+
if (!json.parse_fully_trusted_file(m_dev_path))
347347
{
348348
return false;
349349
}
@@ -410,7 +410,7 @@ bool runtime_config_t::ensure_parsed()
410410
}
411411

412412
json_parser_t json;
413-
if (!json.parse_file(m_path))
413+
if (!json.parse_fully_trusted_file(m_path))
414414
{
415415
return false;
416416
}

0 commit comments

Comments
 (0)