Skip to content

Commit

Permalink
src: readlink("/proc/self/exe") -> uv_exename()
Browse files Browse the repository at this point in the history
This commit also adds error handling. A THP-enabled build terminated
with an out-of-memory error on a system without /proc because it cast
the -1 from readlink() to size_t (i.e. ULONG_MAX) and then tried to
allocate a string of that size.

PR-URL: #28333
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
bnoordhuis authored and targos committed Aug 2, 2019
1 parent a28db5f commit 32cf344
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/large_pages/node_large_page.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,12 @@ static struct text_region FindNodeTextRegion() {
std::string exename;
{
char selfexe[PATH_MAX];
ssize_t count = readlink("/proc/self/exe", selfexe, PATH_MAX);
exename = std::string(selfexe, count);

size_t size = sizeof(selfexe);
if (uv_exepath(selfexe, &size))
return nregion;

exename = std::string(selfexe, size);
}

while (std::getline(ifs, map_line)) {
Expand Down

0 comments on commit 32cf344

Please sign in to comment.