Skip to content

Unsound transmute_copy in attr_ck_long, get_date, attr_ck_ulong #55

@5225225

Description

@5225225
---- 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions