crypt32(3/17): Add basic parameter checking to CryptMsgOpenTo*
Juan Lang
juan.lang at gmail.com
Thu Jun 28 19:26:42 CDT 2007
Skipped content of type multipart/alternative-------------- next part --------------
From 1724703cb4ff5899f3317945bd6f3a4ccabe9e4d Mon Sep 17 00:00:00 2001
From: Juan Lang <juanlang at juan.corp.google.com>
Date: Thu, 28 Jun 2007 16:44:33 -0700
Subject: [PATCH] Add basic parameter checking to CryptMsgOpenTo*
---
dlls/crypt32/msg.c | 53 ++++++++++++++++++++++++++++++++++++++++++++--
dlls/crypt32/tests/msg.c | 7 ------
2 files changed, 51 insertions(+), 9 deletions(-)
diff --git a/dlls/crypt32/msg.c b/dlls/crypt32/msg.c
index d00d68e..df891f4 100644
--- a/dlls/crypt32/msg.c
+++ b/dlls/crypt32/msg.c
@@ -16,6 +16,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <stdarg.h>
+#include <stdio.h>
#include "windef.h"
#include "winbase.h"
#include "wincrypt.h"
@@ -24,13 +25,55 @@ #include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(crypt);
+static inline const char *MSG_TYPE_STR(DWORD type)
+{
+ static char buf[25];
+
+ 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:
+ sprintf(buf, "unknown (%d)", type);
+ return buf;
+ }
+}
+
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 +82,12 @@ HCRYPTMSG WINAPI CryptMsgOpenToDecode(DW
{
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,
--
1.4.1
More information about the wine-patches
mailing list