Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion dissect/target/plugins/os/unix/linux/proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,11 @@ def _parse_proc_stat_entry(self) -> dict[str, str | int]:
def _parse_environ(self) -> Iterator[Environ]:
"""Internal function to parse entries in ``/proc/[pid]/environ``."""
# entries in /proc/<pid>/environ are null-terminated
lines = self.get("environ").read_text().split("\x00")
environ_path = self.get("environ")
if not environ_path.exists():
return

lines = environ_path.read_text().split("\x00")

for line in lines:
if line == "":
Expand Down
5 changes: 3 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def fs_linux_proc(fs_linux: VirtualFilesystem) -> VirtualFilesystem:
"proc/1337",
VirtualSymlink(fs, "/proc/1337/fd/4", "socket:[1337]"),
"acquire\x00-p\x00full\x00--proc\x00",
"VAR=1",
"",
),
)
stat_files_data = (
Expand All @@ -253,7 +253,8 @@ def fs_linux_proc(fs_linux: VirtualFilesystem) -> VirtualFilesystem:

fs.map_file_fh(dir + "/stat", BytesIO(stat_files_data[idx].encode()))
fs.map_file_fh(dir + "/cmdline", BytesIO(cmdline.encode()))
fs.map_file_fh(dir + "/environ", BytesIO(environ.encode()))
if environ:
fs.map_file_fh(dir + "/environ", BytesIO(environ.encode()))

# symlink acquire process to self
fs.link("/proc/1337", "/proc/self")
Expand Down
6 changes: 5 additions & 1 deletion tests/plugins/os/unix/linux/test_environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@


def test_environ(target_linux_users: Target, fs_linux_proc: VirtualFilesystem) -> None:
# Reference the fixture to ensure its setup logic runs (side effects).
# Assigned to `_` to suppress "unused variable" linter warnings.
_ = fs_linux_proc

target_linux_users.add_plugin(ProcPlugin)
results = list(target_linux_users.environ())
assert len(results) == 4
assert len(results) == 3