diff options
| author | Steven Fackler <[email protected]> | 2017-03-09 20:28:42 +1100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-03-09 20:28:42 +1100 |
| commit | efe96396ad7e62327adb0af0664aec7ad28b1bc5 (patch) | |
| tree | 9b6f271b7d23aae057b185959c8e3ee87c2419ce | |
| parent | Merge pull request #585 from bluejekyll/master (diff) | |
| parent | Don't allow Stacks to be allocated with a null-ptr (diff) | |
| download | rust-openssl-efe96396ad7e62327adb0af0664aec7ad28b1bc5.tar.xz rust-openssl-efe96396ad7e62327adb0af0664aec7ad28b1bc5.zip | |
Merge pull request #592 from Byron/master
Fix for len() == isize::max() for stacks that are unallocated
| -rw-r--r-- | openssl/src/pkcs12.rs | 18 | ||||
| -rw-r--r-- | openssl/src/stack.rs | 2 | ||||
| -rw-r--r-- | openssl/test/keystore-empty-chain.p12 | bin | 0 -> 2514 bytes |
3 files changed, 19 insertions, 1 deletions
diff --git a/openssl/src/pkcs12.rs b/openssl/src/pkcs12.rs index 9f014af6..31aae536 100644 --- a/openssl/src/pkcs12.rs +++ b/openssl/src/pkcs12.rs @@ -42,7 +42,12 @@ impl Pkcs12Ref { let pkey = PKey::from_ptr(pkey); let cert = X509::from_ptr(cert); - let chain = Stack::from_ptr(chain); + + let chain = if chain.is_null() { + try!(Stack::new()) + } else { + Stack::from_ptr(chain) + }; Ok(ParsedPkcs12 { pkey: pkey, @@ -80,6 +85,7 @@ impl Pkcs12 { pub struct ParsedPkcs12 { pub pkey: PKey, pub cert: X509, + // FIXME Make this Option<Stack> in the next breaking release pub chain: Stack<X509>, } @@ -197,6 +203,16 @@ mod test { } #[test] + fn parse_empty_chain() { + let der = include_bytes!("../test/keystore-empty-chain.p12"); + let pkcs12 = Pkcs12::from_der(der).unwrap(); + let parsed = pkcs12.parse("cassandra").unwrap(); + + assert_eq!(parsed.chain.len(), 0); + assert_eq!(parsed.chain.into_iter().collect::<Vec<_>>().len(), 0); + } + + #[test] fn create() { let subject_name = "ns.example.com"; let rsa = Rsa::generate(2048).unwrap(); diff --git a/openssl/src/stack.rs b/openssl/src/stack.rs index 268afde7..6ac8264c 100644 --- a/openssl/src/stack.rs +++ b/openssl/src/stack.rs @@ -86,6 +86,8 @@ impl<T: Stackable> ForeignType for Stack<T> { #[inline] unsafe fn from_ptr(ptr: *mut T::StackType) -> Stack<T> { + assert!(!ptr.is_null(), "Must not instantiate a Stack from a null-ptr - use Stack::new() in \ + that case"); Stack(ptr) } diff --git a/openssl/test/keystore-empty-chain.p12 b/openssl/test/keystore-empty-chain.p12 Binary files differnew file mode 100644 index 00000000..c39930a5 --- /dev/null +++ b/openssl/test/keystore-empty-chain.p12 |