Do not crash when converting YAML to JSON fails#4110
Do not crash when converting YAML to JSON fails#4110htuch merged 7 commits intoenvoyproxy:masterfrom dio:do-not-crash-config-yaml
Conversation
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
|
|
||
| TEST(UtilityTest, YamlLoadFromStringFail) { | ||
| envoy::config::bootstrap::v2::Bootstrap bootstrap; | ||
| EXPECT_THROW_WITH_MESSAGE(MessageUtil::loadFromYaml("/home/configs/config.yaml", bootstrap), |
There was a problem hiding this comment.
I don't think this path is available in CI? Is it possible to do a more direct test case of the actual issue potentially not even loading from a file?
There was a problem hiding this comment.
This simulates what is described in the issue #3990, that gave input to --config-yaml a file path string (while this config option expects a valid yaml string instead). #3990 (comment)
This doesn't try to load a file. The --config-yaml perceives this as a string (in this case the string value is a file path).
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
|
I'm fixing the approach... |
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
|
It seems fine now. I deferred the checking until at the protobuf util. |
mattklein123
left a comment
There was a problem hiding this comment.
Thanks, so what was wrong with the previous approach for reference?
source/common/protobuf/utility.cc
Outdated
| void MessageUtil::loadFromYaml(const std::string& yaml, Protobuf::Message& message) { | ||
| const std::string json = Json::Factory::loadFromYamlString(yaml)->asJsonString(); | ||
| loadFromJson(json, message); | ||
| const auto& loaded_object = Json::Factory::loadFromYamlString(yaml); |
There was a problem hiding this comment.
nit: technically this should not be a reference so I would remove &.
source/common/protobuf/utility.cc
Outdated
| const std::string json = Json::Factory::loadFromYamlString(yaml)->asJsonString(); | ||
| loadFromJson(json, message); | ||
| const auto& loaded_object = Json::Factory::loadFromYamlString(yaml); | ||
| // Load to the message if the loaded object has type Object or Array. |
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
|
The previous attempt failed to pass the following unit tests, envoy/test/common/json/json_loader_test.cc Lines 421 to 467 in 5a49ba6 |
mattklein123
left a comment
There was a problem hiding this comment.
Thanks, LGTM. It would be good if @htuch could take a quick look since he is more familiar w/ the YAML parsing code.
| loadFromJson(json, message); | ||
| const auto loaded_object = Json::Factory::loadFromYamlString(yaml); | ||
| // Load the message if the loaded object has type Object or Array. | ||
| if (loaded_object->isObject() || loaded_object->isArray()) { |
There was a problem hiding this comment.
I guess this works because 100% of the time we use loadFromYaml it's for non-trivial compound types.
* origin/master: (38 commits) test: add tests for corner-cases around sending requests before run() starts or after run() ends. (envoyproxy#4114) perf: reduce the memory usage of LC Trie construction (envoyproxy#4117) test: moving redundant code in websocket_integration_test to utilities (envoyproxy#4127) test: make YamlLoadFromStringFail less picky about error msg. (envoyproxy#4141) rbac: add rbac network filter. (envoyproxy#4083) fuzz: route lookup and header finalization fuzzer. (envoyproxy#4116) Set content-type and content-length (envoyproxy#4113) fault: use FractionalPercent for percent (envoyproxy#3978) test: Fix inverted exact match logic in IntegrationTcpClient::waitForData() (envoyproxy#4134) Added cluster_name to load assignment config for static cluster (envoyproxy#4123) ssl: refactor ContextConfig to use TlsCertificateConfig (envoyproxy#4115) syscall: refactor OsSysCalls for deeper errno latching (envoyproxy#4111) thrift_proxy: fix oneway bugs (envoyproxy#4025) Do not crash when converting YAML to JSON fails (envoyproxy#4110) config: allow unknown fields flag (take 2) (envoyproxy#4096) Use a jittered backoff strategy for handling HdsDelegate stream/connection failures (envoyproxy#4108) bazel: use GCS remote cache (envoyproxy#4050) Add thread local cache of overload action states (envoyproxy#4090) Added TCP healthcheck capabilities to the HdsDelegate (envoyproxy#4079) secret: add secret provider interface and use it for TlsCertificates (envoyproxy#4086) ... Signed-off-by: Snow Pettersen <snowp@squareup.com>
Description: Do not crash when converting YAML to JSON fails.
Risk Level: Low
Testing: Added
Docs Changes: N/A
Release Notes: N/A
Fixes #3990
Signed-off-by: Dhi Aurrahman dio@tetrate.io