Skip to content

Commit

Permalink
src: perform bounds checking on error source line
Browse files Browse the repository at this point in the history
  • Loading branch information
addaleax committed May 29, 2020
1 parent 9949a2e commit 7d7a9b4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/node_errors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,18 @@ static std::string GetErrorSource(Isolate* isolate,
MaybeLocal<String> source_line_maybe = message->GetSourceLine(context);
node::Utf8Value encoded_source(isolate, source_line_maybe.ToLocalChecked());
std::string sourceline(*encoded_source, encoded_source.length());
*added_exception_line = false;

// If source maps have been enabled, the exception line will instead be
// added in the JavaScript context:
Environment* env = Environment::GetCurrent(isolate);
const bool has_source_map_url =
!message->GetScriptOrigin().SourceMapUrl().IsEmpty();
if (has_source_map_url && env->source_maps_enabled()) {
*added_exception_line = false;
return sourceline;
}

if (sourceline.find("node-do-not-add-exception-line") != std::string::npos) {
*added_exception_line = false;
return sourceline;
}

Expand Down Expand Up @@ -116,6 +115,12 @@ static std::string GetErrorSource(Isolate* isolate,
sourceline.c_str());
CHECK_GT(buf.size(), 0);

if (start >= end ||
start < 0 ||
static_cast<size_t>(end) > sourceline.size()) {
return buf;
}

constexpr int kUnderlineBufsize = 1020;
char underline_buf[kUnderlineBufsize + 4];
int off = 0;
Expand Down

0 comments on commit 7d7a9b4

Please sign in to comment.