Files
v/vlib/os/executable_path_test.v
9694a71767 vlib/os: build executable() path from the readlink length, not a NUL scan (#30441)
* vlib/os: build executable() path from the readlink length, not a NUL scan

readlink never appends a terminator, but the Linux, NetBSD and
DragonFly branches passed the buffer to tos_clone, which scans for
one with vstrlen. A link target filling the whole buffer over-reads
the stack, and a truncated over-long path is silently returned.
Use the returned byte count via vstring_with_len().clone(), the same
pattern db.mysql and others use. The FreeBSD sysctl branch is a
different API and is left alone.

Fixes https://github.com/vlang/v/issues/30158

* os: cover executable path identity and document readlink lengths

---------

Co-authored-by: qp <168933756+gabytz777@users.noreply.github.com>
Co-authored-by: Alexander Medvednikov <alexander@medvednikov.com>
2026-10-14 04:20:53 +03:00

10 lines
253 B
V

import os
fn test_executable_returns_complete_process_path() {
executable := os.executable()
assert executable.len > 0
assert !executable.contains('\x00')
assert os.is_file(executable)
assert os.real_path(executable) == os.real_path(os.args[0])
}