Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsound transmute_copy in attr_ck_long, get_date, attr_ck_ulong #55

Closed
5225225 opened this issue Jul 8, 2022 · 0 comments · Fixed by #56
Closed

Unsound transmute_copy in attr_ck_long, get_date, attr_ck_ulong #55

5225225 opened this issue Jul 8, 2022 · 0 comments · Fixed by #56

Comments

@5225225
Copy link
Contributor

5225225 commented Jul 8, 2022

---- tests::attr_ck_long stdout ----
CK_ATTRIBUTE { attrType: "0x402", pValue: [214, 255, 255, 255, 255, 255, 255, 255], ulValueLen: 8 }
[src/types.rs:838] std::mem::size_of::<CK_LONG>() = 8
[src/types.rs:839] std::mem::size_of_val(&*self.pValue) = 1
thread 'tests::attr_ck_long' panicked at 'cannot transmute_copy if U is larger than T', /home/jess/src/rust/library/co
re/src/mem/mod.rs:1043:5
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::mem::transmute_copy
             at /home/jess/src/rust/library/core/src/mem/mod.rs:1043:5
   3: pkcs11::types::CK_ATTRIBUTE::get_ck_long
             at ./src/types.rs:842:21
   4: pkcs11::tests::attr_ck_long
             at ./src/tests.rs:544:24
   5: pkcs11::tests::attr_ck_long::{{closure}}
             at ./src/tests.rs:540:1
   6: core::ops::function::FnOnce::call_once
             at /home/jess/src/rust/library/core/src/ops/function.rs:248:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

---- tests::attr_date stdout ----
CK_ATTRIBUTE { attrType: "0x3", pValue: [0, 0, 0, 0, 0, 0, 0, 0], ulValueLen: 8 }
thread 'tests::attr_date' panicked at 'cannot transmute_copy if U is larger than T', /home/jess/src/rust/library/core/
src/mem/mod.rs:1043:5
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::mem::transmute_copy
             at /home/jess/src/rust/library/core/src/mem/mod.rs:1043:5
   3: pkcs11::types::CK_ATTRIBUTE::get_date
             at ./src/types.rs:922:21
   4: pkcs11::tests::attr_date
             at ./src/tests.rs:579:15
   5: pkcs11::tests::attr_date::{{closure}}
             at ./src/tests.rs:575:1
   6: core::ops::function::FnOnce::call_once
             at /home/jess/src/rust/library/core/src/ops/function.rs:248:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

---- tests::attr_ck_ulong stdout ----
CK_ATTRIBUTE { attrType: "0x402", pValue: [42, 0, 0, 0, 0, 0, 0, 0], ulValueLen: 8 }
thread 'tests::attr_ck_ulong' panicked at 'cannot transmute_copy if U is larger than T', /home/jess/src/rust/library/c
ore/src/mem/mod.rs:1043:5
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::mem::transmute_copy
             at /home/jess/src/rust/library/core/src/mem/mod.rs:1043:5
   3: pkcs11::types::CK_ATTRIBUTE::get_ck_ulong
             at ./src/types.rs:817:21
   4: pkcs11::tests::attr_ck_ulong
             at ./src/tests.rs:534:25
   5: pkcs11::tests::attr_ck_ulong::{{closure}}
             at ./src/tests.rs:530:1
   6: core::ops::function::FnOnce::call_once
             at /home/jess/src/rust/library/core/src/ops/function.rs:248:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Runtime checks for transmute_copy's invariant that the output type is no larger than the input type are being added in rust-lang/rust#98839 , and this crate looks to be one that will get affected by that.

Looks like the transmute_copy should instead be a pointer cast and a read.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant