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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Ben Noordhuis 2019-06-21 11:16:05 +02:00 committed by Rich Trott
parent 89344f5bee
commit 54ae530951

View File

@ -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)) {