Skip to content

Commit ed176cb

Browse files
authored
Merge pull request #14618 from jonhermansen/freebsd-path-null-terminator
fix(FreeBSD): remove null terminator from executable path
2 parents c9fe290 + 3ff8d0e commit ed176cb

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/libutil/current-process.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ std::optional<Path> getSelfExe()
134134
return std::nullopt;
135135
}
136136

137+
// FreeBSD's sysctl(KERN_PROC_PATHNAME) includes the null terminator in
138+
// pathLen. Strip it to prevent Nix evaluation errors when the path is
139+
// serialized to JSON and evaluated as a Nix string.
140+
path.pop_back();
141+
137142
return Path(path.begin(), path.end());
138143
#else
139144
return std::nullopt;

0 commit comments

Comments
 (0)