Skip to content

Commit 40cee72

Browse files
authored
Merge pull request #85350 from aeu/fix-readlink-null-termination
Fix missing null terminator in runtime path resolution on Linux
2 parents deba793 + cfbe70d commit 40cee72

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

stdlib/public/runtime/Paths.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,9 @@ _swift_initRuntimePath(void *) {
548548
// this is needed with Musl when statically linking because in that case
549549
// dladdr() does nothing.
550550
char pathBuf[4096];
551-
ssize_t len = readlink("/proc/self/exe", pathBuf, sizeof(pathBuf));
552-
if (len > 0 && len < sizeof(pathBuf)) {
551+
ssize_t len = readlink("/proc/self/exe", pathBuf, sizeof(pathBuf)-1);
552+
if (len > 0 ) {
553+
pathBuf[len] = '\0';
553554
runtimePath = ::strdup(pathBuf);
554555
return;
555556
}

0 commit comments

Comments
 (0)