Skip to content

makeBinaryWrapper: fix read past NUL - #541658

Closed
accelbread wants to merge 2 commits into
NixOS:masterfrom
accelbread:binwrapper-fix
Closed

accelbread wants to merge 2 commits into
NixOS:masterfrom
accelbread:binwrapper-fix

Conversation

@accelbread

Copy link
Copy Markdown
Contributor

This fixes a bug in makeBinaryWrapper which corrupts path-like environment variables when using the prefix option and the path had an existing duplicate element in the last element. In this case the nul byte is skipped and the value is overread (likely into the next element).

This bug causes issues as env vars intended values get concatenated with neighboring values.

On my system this causes Gstreamer directories to be appended onto GIO modules path. This causes every GIO application to dlload all gstreamer modules, creating a flood of error logs, and also running initialization code in each of those modules.

This was also interesting to debug as the env variables passed to the program look completely correct since they are corrupted by makeBinaryWrapper; observing what pam outputs or what gets passed to the program look correct. This allows manipulating path-like env vars such that they appear different to the application executing the program and the actual program under the wrapper.

The makeBinaryWrapper tests were also failing (at least since the commit that introduced the above bug), so I have updated those tests to work as a separate commit before my change, and updated them as needed as part of the change commit. I also added a new test for this case.

Things done

@accelbread accelbread changed the title Binwrapper fix makeBinaryWrapper: fix read past NUL Jul 14, 2026
When setting a prefix for a path-like environment variable, the
deduplication code in set_env_prefix reads past the NUL byte at the end
of the env val and into the next entry. This corrupts the resultant env
value with data from the next env var, or other data sitting after it.
@accelbread

Copy link
Copy Markdown
Contributor Author

Oops, targeted master; re-opening against staging

@nixpkgs-branch-check nixpkgs-branch-check Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR's base branch is set to master, but this PR causes 62493 rebuilds.
It is therefore considered a mass rebuild.
Please change the base branch to the right base branch for your changes (probably staging).

@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 9.needs: reviewer This PR currently has no reviewers requested and needs attention. 10.rebuild-nixos-tests This PR causes rebuilds for all NixOS tests and should normally target the staging branches. labels Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

9.needs: reviewer This PR currently has no reviewers requested and needs attention. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 10.rebuild-nixos-tests This PR causes rebuilds for all NixOS tests and should normally target the staging branches.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant