Skip to content

Commit 7d7a9b4

Browse files
committed
src: perform bounds checking on error source line
Fixes: nodejs#33578
1 parent 9949a2e commit 7d7a9b4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/node_errors.cc

+7-2
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,18 @@ static std::string GetErrorSource(Isolate* isolate,
5656
MaybeLocal<String> source_line_maybe = message->GetSourceLine(context);
5757
node::Utf8Value encoded_source(isolate, source_line_maybe.ToLocalChecked());
5858
std::string sourceline(*encoded_source, encoded_source.length());
59+
*added_exception_line = false;
5960

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

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

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

118+
if (start >= end ||
119+
start < 0 ||
120+
static_cast<size_t>(end) > sourceline.size()) {
121+
return buf;
122+
}
123+
119124
constexpr int kUnderlineBufsize = 1020;
120125
char underline_buf[kUnderlineBufsize + 4];
121126
int off = 0;

0 commit comments

Comments
 (0)