Skip to content

Commit 9783b88

Browse files
committed
Refactor: fix possible out-of-bounds read when reporting errors
vscode_error_formatter::append_diagnostic assumes that the error code string_view is 0-terminated. It currently is 0-terminated, but this relying on this is a bad idea. Copy the error code into an std::string to force null termination. (We were already creating a std::string anyway for other purposes.) This commit should not change behavior.
1 parent 0647263 commit 9783b88

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

plugin/vscode/quick-lint-js/vscode-error-reporter.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,18 @@ class vscode_error_formatter
8686
/*severity=*/severity,
8787
});
8888

89+
std::string code_string(code);
8990
::Napi::Value uri = this->vscode_->uri_class.New(
9091
{/*scheme=*/::Napi::String::New(this->env_, "https"),
9192
/*authority=*/::Napi::String::New(this->env_, "quick-lint-js.com"),
9293
/*path=*/
93-
::Napi::String::New(this->env_, "/errors/" + std::string(code) + "/"),
94+
::Napi::String::New(this->env_, "/errors/" + code_string + "/"),
9495
/*query=*/::Napi::String::New(this->env_, ""),
9596
/*fragment=*/::Napi::String::New(this->env_, "")});
9697

9798
::Napi::Object code_obj = ::Napi::Object::New(this->env_);
9899
code_obj.Set("target", uri);
99-
code_obj.Set("value", code.data());
100+
code_obj.Set("value", code_string);
100101

101102
diag.Set("code", code_obj);
102103
diag.Set("source", ::Napi::String::New(this->env_, "quick-lint-js"));

0 commit comments

Comments
 (0)