@@ -55,19 +55,18 @@ static std::string GetErrorSource(Isolate* isolate,
55
55
MaybeLocal<String> source_line_maybe = message->GetSourceLine (context);
56
56
node::Utf8Value encoded_source (isolate, source_line_maybe.ToLocalChecked ());
57
57
std::string sourceline (*encoded_source, encoded_source.length ());
58
+ *added_exception_line = false ;
58
59
59
60
// If source maps have been enabled, the exception line will instead be
60
61
// added in the JavaScript context:
61
62
Environment* env = Environment::GetCurrent (isolate);
62
63
const bool has_source_map_url =
63
64
!message->GetScriptOrigin ().SourceMapUrl ().IsEmpty ();
64
65
if (has_source_map_url && env->source_maps_enabled ()) {
65
- *added_exception_line = false ;
66
66
return sourceline;
67
67
}
68
68
69
69
if (sourceline.find (" node-do-not-add-exception-line" ) != std::string::npos) {
70
- *added_exception_line = false ;
71
70
return sourceline;
72
71
}
73
72
@@ -114,6 +113,13 @@ static std::string GetErrorSource(Isolate* isolate,
114
113
linenum,
115
114
sourceline.c_str ());
116
115
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
+ }
117
123
118
124
constexpr int kUnderlineBufsize = 1020 ;
119
125
char underline_buf[kUnderlineBufsize + 4 ];
@@ -136,7 +142,6 @@ static std::string GetErrorSource(Isolate* isolate,
136
142
CHECK_LE (off, kUnderlineBufsize );
137
143
underline_buf[off++] = ' \n ' ;
138
144
139
- *added_exception_line = true ;
140
145
return buf + std::string (underline_buf, off);
141
146
}
142
147
0 commit comments