trifectatechfoundation / sudo-rs

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

Fix builds on arm by changing from i8 to c_char. #653

Closed dlorenc closed 1 year ago

dlorenc commented 1 year ago

When I built on arm (aarch64), I got this compiler error:

   Compiling sudo-rs v0.2.0-dev.20230703 (/sudo-rs)
error[E0308]: mismatched types
   --> src/pam/mod.rs:217:44
    |
217 |         let cstr = unsafe { CStr::from_ptr(data as *const i8) };
    |                             -------------- ^^^^^^^^^^^^^^^^^ expected `*const u8`, found `*const i8`
    |                             |
    |                             arguments to this function are incorrect
    |
    = note: expected raw pointer `*const u8`
               found raw pointer `*const i8`
note: associated function defined here
   --> /home/build/rustc-1.70.0-src/library/core/src/ffi/c_str.rs:260:25

For more information about this error, try `rustc --explain E0308`.

After some research, I learned that this is an architecture issue - on many platforms char is mapped to i8, but not on aarch64. Here's a source: https://github.com/fede1024/rust-rdkafka/issues/121

With this change it now builds successfully on arm!

dlorenc commented 1 year ago

Thanks! Can you run a cargo fmt over your changes? (see the CI output).

That was fast, thanks!

dlorenc commented 1 year ago

Looks like a flake or unrelated to the PR...

squell commented 1 year ago

Looks like a flake or unrelated to the PR...

Totally; code coverage collection has been failing us since yesterday. Probably going to remove that from the CI.

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 100.00% and project coverage change: -6.15 :warning:

Comparison is base (824a4ad) 86.35% compared to head (25d8be3) 80.21%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #653 +/- ## ========================================== - Coverage 86.35% 80.21% -6.15% ========================================== Files 64 58 -6 Lines 8680 5968 -2712 ========================================== - Hits 7496 4787 -2709 + Misses 1184 1181 -3 ``` | [Impacted Files](https://app.codecov.io/gh/memorysafety/sudo-rs/pull/653?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=memorysafety) | Coverage Δ | | |---|---|---| | [src/pam/mod.rs](https://app.codecov.io/gh/memorysafety/sudo-rs/pull/653?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=memorysafety#diff-c3JjL3BhbS9tb2QucnM=) | `91.18% <100.00%> (ø)` | | ... and [44 files with indirect coverage changes](https://app.codecov.io/gh/memorysafety/sudo-rs/pull/653/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.

dlorenc commented 1 year ago

Thanks for deflaking!