From 13e7cc155149cf6e7c3789955e2d48be0a42cc26 Mon Sep 17 00:00:00 2001 From: Victor Wagner Date: Mon, 20 Jun 2016 17:01:30 +0300 Subject: [PATCH] Check for CMS parsing error and don't pass None to CMS_get0_type. Fixes #3 --- ctypescrypto/cms.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ctypescrypto/cms.py b/ctypescrypto/cms.py index 1e53387..685d52b 100644 --- a/ctypescrypto/cms.py +++ b/ctypescrypto/cms.py @@ -59,6 +59,8 @@ def CMS(data, format="PEM"): ptr = libcrypto.PEM_read_bio_CMS(bio.bio, None, None, None) else: ptr = libcrypto.d2i_CMS_bio(bio.bio, None) + if ptr is None: + raise CMSError("Error parsing CMS data") typeoid = Oid(libcrypto.OBJ_obj2nid(libcrypto.CMS_get0_type(ptr))) if typeoid.shortname() == "pkcs7-signedData": return SignedData(ptr) -- 2.39.5