Skip to content

Commit 32cf344

Browse files
bnoordhuistargos
authored andcommitted
src: readlink("/proc/self/exe") -> uv_exename()
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 <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent a28db5f commit 32cf344

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/large_pages/node_large_page.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,12 @@ static struct text_region FindNodeTextRegion() {
115115
std::string exename;
116116
{
117117
char selfexe[PATH_MAX];
118-
ssize_t count = readlink("/proc/self/exe", selfexe, PATH_MAX);
119-
exename = std::string(selfexe, count);
118+
119+
size_t size = sizeof(selfexe);
120+
if (uv_exepath(selfexe, &size))
121+
return nregion;
122+
123+
exename = std::string(selfexe, size);
120124
}
121125

122126
while (std::getline(ifs, map_line)) {

0 commit comments

Comments
 (0)