trifectatechfoundation / sudo-rs

A memory safe implementation of sudo and su.
Other
2.9k stars 79 forks source link

Close all the file descriptors before running the command #621

Closed pvdrz closed 1 year ago

pvdrz commented 1 year ago

Describe the changes done on this pull request This PR introduces a new FileCloser type with a FileCloser::close_the_universe method able to close every file that's not stdin/out/err or explicitly preserved using FileCloser::except.

close_the_universe is called just before Command::exec is run. The only files preserved using except are the pipe used for error reporting if Command::exec fails and the duped versions of the follower side of the pty.

The exec::no_pty module was refactored to use fork + Command::exec instead of Command::spawn to be able to call close_the_universe without interfering with Command::spawn's inner workings.

Additionally the calls to exit were replaced by _exit in an attempt to fix the spurious errors about *.profraw files being corrupt.

Pull Request Checklist

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 86.95% and project coverage change: +0.46 :tada:

Comparison is base (bb0d6bc) 86.34% compared to head (5f87e79) 86.80%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #621 +/- ## ========================================== + Coverage 86.34% 86.80% +0.46% ========================================== Files 61 61 Lines 8481 8605 +124 ========================================== + Hits 7323 7470 +147 + Misses 1158 1135 -23 ``` | [Impacted Files](https://app.codecov.io/gh/memorysafety/sudo-rs/pull/621?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=memorysafety) | Coverage Δ | | |---|---|---| | [src/exec/use\_pty/monitor.rs](https://app.codecov.io/gh/memorysafety/sudo-rs/pull/621?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=memorysafety#diff-c3JjL2V4ZWMvdXNlX3B0eS9tb25pdG9yLnJz) | `55.98% <21.42%> (+0.16%)` | :arrow_up: | | [src/exec/no\_pty.rs](https://app.codecov.io/gh/memorysafety/sudo-rs/pull/621?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=memorysafety#diff-c3JjL2V4ZWMvbm9fcHR5LnJz) | `73.68% <91.42%> (+2.55%)` | :arrow_up: | | [src/system/mod.rs](https://app.codecov.io/gh/memorysafety/sudo-rs/pull/621?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=memorysafety#diff-c3JjL3N5c3RlbS9tb2QucnM=) | `89.56% <94.93%> (+3.05%)` | :arrow_up: | | [src/exec/use\_pty/parent.rs](https://app.codecov.io/gh/memorysafety/sudo-rs/pull/621?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=memorysafety#diff-c3JjL2V4ZWMvdXNlX3B0eS9wYXJlbnQucnM=) | `75.40% <100.00%> (+0.34%)` | :arrow_up: | ... and [4 files with indirect coverage changes](https://app.codecov.io/gh/memorysafety/sudo-rs/pull/621/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=memorysafety)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

github-actions[bot] commented 1 year ago

Number of dependencies and binary size impact report

Metric main PR #621 Delta
Direct dependencies 5 5 -
Total dependencies 10 10 -
Binary size 1.1 MiB 1 MiB -0.5%
Text size 630.5 KiB 630.2 KiB -
Dependencies diff ```diff └─ sudo-rs [v0.2.0-dev.20230627] ├─ glob [v0.3.1] ├─ libc [v0.2.147] ├─ log [v0.4.19] ├─ signal-hook [v0.3.15] | ├─ libc [v0.2.147] | ├─ signal-hook-registry [v1.4.1] | | └─ libc [v0.2.147] | └─ cc [v1.0.79] └─ signal-hook-registry [v1.4.1] ```