Skip to content

Commit 23fc680

Browse files
GrinZerobugyaluwang
authored andcommitted
inspector,test: reject malformed initiator stack traces
1 parent f14e24c commit 23fc680

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

β€Žnode.gypβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,7 @@
14181418
# TODO(legendecas): make node_inspector.gypi a dependable target.
14191419
'<(SHARED_INTERMEDIATE_DIR)', # for inspector
14201420
'<(SHARED_INTERMEDIATE_DIR)/src', # for inspector
1421+
'<(SHARED_INTERMEDIATE_DIR)/inspector-generated-output-root/include',
14211422
],
14221423
'dependencies': [
14231424
'deps/inspector_protocol/inspector_protocol.gyp:crdtp',

β€Žsrc/inspector/network_agent.ccβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ NetworkAgent::createInitiatorFromObject(v8::Local<v8::Context> context,
167167
protocol::ValueConversions<v8_inspector::protocol::Runtime::API::
168168
StackTrace>::fromValue(stack_value.get(),
169169
&errors);
170-
if (!stack) {
170+
if (!stack || !errors.Errors().empty()) {
171171
ThrowEventError(isolate, "Invalid initiator.stack in event");
172172
return {};
173173
}

β€Žtest/cctest/inspector/test_node_protocol.ccβ€Ž

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@
22
#include "gtest/gtest.h"
33
#include "inspector/node_json.h"
44
#include "node/inspector/protocol/Protocol.h"
5+
#include "node/inspector/protocol/Runtime.h"
56

67
namespace node {
78
namespace inspector {
89
namespace protocol {
910
namespace {
1011

12+
class MalformedSerializedValue : public Value {
13+
public:
14+
MalformedSerializedValue() : Value(TypeObject) {}
15+
16+
void AppendSerialized(std::vector<uint8_t>* out) const override {
17+
out->push_back(0xff);
18+
}
19+
};
20+
1121
TEST(InspectorProtocol, Utf8StringSerDes) {
1222
constexpr const char* kKey = "unicode_key";
1323
constexpr const char* kValue = "CJK 汉字 🍱 πŸ§‘β€πŸ§‘β€πŸ§’β€πŸ§’";
@@ -27,6 +37,18 @@ TEST(InspectorProtocol, Utf8StringSerDes) {
2737
CHECK_EQ(parsed_value, std::string(kValue));
2838
}
2939

40+
TEST(InspectorProtocol, StackTraceImportRejectsMalformedBinary) {
41+
MalformedSerializedValue value;
42+
ErrorSupport errors;
43+
44+
auto stack =
45+
ValueConversions<v8_inspector::protocol::Runtime::API::StackTrace>::
46+
fromValue(&value, &errors);
47+
48+
EXPECT_EQ(stack, nullptr);
49+
EXPECT_FALSE(errors.Errors().empty());
50+
}
51+
3052
} // namespace
3153
} // namespace protocol
3254
} // namespace inspector

0 commit comments

Comments
Β (0)