@@ -55,19 +55,18 @@ static std::string GetErrorSource(Isolate* isolate,
5555 MaybeLocal<String> source_line_maybe = message->GetSourceLine (context);
5656 node::Utf8Value encoded_source (isolate, source_line_maybe.ToLocalChecked ());
5757 std::string sourceline (*encoded_source, encoded_source.length ());
58+ *added_exception_line = false ;
5859
5960 // If source maps have been enabled, the exception line will instead be
6061 // added in the JavaScript context:
6162 Environment* env = Environment::GetCurrent (isolate);
6263 const bool has_source_map_url =
6364 !message->GetScriptOrigin ().SourceMapUrl ().IsEmpty ();
6465 if (has_source_map_url && env->source_maps_enabled ()) {
65- *added_exception_line = false ;
6666 return sourceline;
6767 }
6868
6969 if (sourceline.find (" node-do-not-add-exception-line" ) != std::string::npos) {
70- *added_exception_line = false ;
7170 return sourceline;
7271 }
7372
@@ -114,6 +113,13 @@ static std::string GetErrorSource(Isolate* isolate,
114113 linenum,
115114 sourceline.c_str ());
116115 CHECK_GT (buf.size (), 0 );
116+ *added_exception_line = true ;
117+
118+ if (start > end ||
119+ start < 0 ||
120+ static_cast <size_t >(end) > sourceline.size ()) {
121+ return buf;
122+ }
117123
118124 constexpr int kUnderlineBufsize = 1020 ;
119125 char underline_buf[kUnderlineBufsize + 4 ];
@@ -136,7 +142,6 @@ static std::string GetErrorSource(Isolate* isolate,
136142 CHECK_LE (off, kUnderlineBufsize );
137143 underline_buf[off++] = ' \n ' ;
138144
139- *added_exception_line = true ;
140145 return buf + std::string (underline_buf, off);
141146}
142147
0 commit comments