GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — src: perform bounds checking on error source line · jigfox/node@4678e44

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • node_errors.cc
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/node_errors.cc‎

Copy file name to clipboardExpand all lines: src/node_errors.cc
+8-3Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.