Module: wine Branch: master Commit: 1c837f16ace9217bcad618149c85d6932542fde6 URL: http://source.winehq.org/git/wine.git/?a=commit;h=1c837f16ace9217bcad618149c...
Author: Juan Lang juan.lang@gmail.com Date: Thu Jun 28 16:44:33 2007 -0700
crypt32: Add basic parameter checking to CryptMsgOpenTo*.
---
dlls/crypt32/msg.c | 49 ++++++++++++++++++++++++++++++++++++++++++++- dlls/crypt32/tests/msg.c | 7 ------ 2 files changed, 47 insertions(+), 9 deletions(-)
diff --git a/dlls/crypt32/msg.c b/dlls/crypt32/msg.c index d00d68e..a25affa 100644 --- a/dlls/crypt32/msg.c +++ b/dlls/crypt32/msg.c @@ -24,13 +24,52 @@
WINE_DEFAULT_DEBUG_CHANNEL(crypt);
+static inline const char *MSG_TYPE_STR(DWORD type) +{ + switch (type) + { +#define _x(x) case (x): return #x + _x(CMSG_DATA); + _x(CMSG_SIGNED); + _x(CMSG_ENVELOPED); + _x(CMSG_SIGNED_AND_ENVELOPED); + _x(CMSG_HASHED); + _x(CMSG_ENCRYPTED); +#undef _x + default: + return wine_dbg_sprintf("unknown (%d)", type); + } +} + HCRYPTMSG WINAPI CryptMsgOpenToEncode(DWORD dwMsgEncodingType, DWORD dwFlags, DWORD dwMsgType, const void *pvMsgEncodeInfo, LPSTR pszInnerContentObjID, PCMSG_STREAM_INFO pStreamInfo) { - FIXME("(%08x, %08x, %08x, %p, %s, %p): stub\n", dwMsgEncodingType, dwFlags, + HCRYPTMSG msg = NULL; + + TRACE("(%08x, %08x, %08x, %p, %s, %p)\n", dwMsgEncodingType, dwFlags, dwMsgType, pvMsgEncodeInfo, debugstr_a(pszInnerContentObjID), pStreamInfo); - return NULL; + + if (GET_CMSG_ENCODING_TYPE(dwMsgEncodingType) != PKCS_7_ASN_ENCODING) + { + SetLastError(E_INVALIDARG); + return NULL; + } + switch (dwMsgType) + { + case CMSG_DATA: + case CMSG_SIGNED: + case CMSG_ENVELOPED: + case CMSG_HASHED: + FIXME("unimplemented for type %s\n", MSG_TYPE_STR(dwMsgType)); + break; + case CMSG_SIGNED_AND_ENVELOPED: + case CMSG_ENCRYPTED: + /* defined but invalid, fall through */ + default: + SetLastError(CRYPT_E_INVALID_MSG_TYPE); + } + return msg; }
HCRYPTMSG WINAPI CryptMsgOpenToDecode(DWORD dwMsgEncodingType, DWORD dwFlags, @@ -39,6 +78,12 @@ HCRYPTMSG WINAPI CryptMsgOpenToDecode(DWORD dwMsgEncodingType, DWORD dwFlags, { FIXME("(%08x, %08x, %08x, %08lx, %p, %p): stub\n", dwMsgEncodingType, dwFlags, dwMsgType, hCryptProv, pRecipientInfo, pStreamInfo); + + if (GET_CMSG_ENCODING_TYPE(dwMsgEncodingType) != PKCS_7_ASN_ENCODING) + { + SetLastError(E_INVALIDARG); + return NULL; + } return NULL; }
diff --git a/dlls/crypt32/tests/msg.c b/dlls/crypt32/tests/msg.c index acdbeca..035a40c 100644 --- a/dlls/crypt32/tests/msg.c +++ b/dlls/crypt32/tests/msg.c @@ -43,19 +43,16 @@ static void test_msg_open_to_encode(void) /* Bad encodings */ SetLastError(0xdeadbeef); msg = CryptMsgOpenToEncode(0, 0, 0, NULL, NULL, NULL); - todo_wine { ok(!msg && GetLastError() == E_INVALIDARG, "Expected E_INVALIDARG, got %x\n", GetLastError()); SetLastError(0xdeadbeef); msg = CryptMsgOpenToEncode(X509_ASN_ENCODING, 0, 0, NULL, NULL, NULL); ok(!msg && GetLastError() == E_INVALIDARG, "Expected E_INVALIDARG, got %x\n", GetLastError()); - }
/* Bad message types */ SetLastError(0xdeadbeef); msg = CryptMsgOpenToEncode(PKCS_7_ASN_ENCODING, 0, 0, NULL, NULL, NULL); - todo_wine { ok(!msg && GetLastError() == CRYPT_E_INVALID_MSG_TYPE, "Expected CRYPT_E_INVALID_MSG_TYPE, got %x\n", GetLastError()); SetLastError(0xdeadbeef); @@ -73,7 +70,6 @@ static void test_msg_open_to_encode(void) NULL, NULL); ok(!msg && GetLastError() == CRYPT_E_INVALID_MSG_TYPE, "Expected CRYPT_E_INVALID_MSG_TYPE, got %x\n", GetLastError()); - } }
static void test_msg_open_to_decode(void) @@ -83,13 +79,11 @@ static void test_msg_open_to_decode(void)
SetLastError(0xdeadbeef); msg = CryptMsgOpenToDecode(0, 0, 0, 0, NULL, NULL); - todo_wine ok(!msg && GetLastError() == E_INVALIDARG, "Expected E_INVALIDARG, got %x\n", GetLastError());
/* Bad encodings */ SetLastError(0xdeadbeef); - todo_wine { msg = CryptMsgOpenToDecode(X509_ASN_ENCODING, 0, 0, 0, NULL, NULL); ok(!msg && GetLastError() == E_INVALIDARG, "Expected E_INVALIDARG, got %x\n", GetLastError()); @@ -97,7 +91,6 @@ static void test_msg_open_to_decode(void) msg = CryptMsgOpenToDecode(X509_ASN_ENCODING, 0, CMSG_DATA, 0, NULL, NULL); ok(!msg && GetLastError() == E_INVALIDARG, "Expected E_INVALIDARG, got %x\n", GetLastError()); - }
/* The message type can be explicit... */ msg = CryptMsgOpenToDecode(PKCS_7_ASN_ENCODING, 0, CMSG_DATA, 0, NULL,