[PATCH v3 1/5] ncrypt: Make NCryptOpenStorageProvider return a valid stub pointer.

Santino Mazza mazzasantino1206 at gmail.com
Tue Feb 15 12:43:11 CST 2022


Some applications crash when the storage provider its null.

Signed-off-by: Santino Mazza <mazzasantino1206 at gmail.com>
---
 dlls/ncrypt/main.c            | 16 +++++++++-
 dlls/ncrypt/ncrypt_internal.h | 56 +++++++++++++++++++++++++++++++++++
 dlls/ncrypt/tests/ncrypt.c    |  2 +-
 3 files changed, 72 insertions(+), 2 deletions(-)
 create mode 100644 dlls/ncrypt/ncrypt_internal.h

diff --git a/dlls/ncrypt/main.c b/dlls/ncrypt/main.c
index f23b239d93f..7f844bf9e85 100644
--- a/dlls/ncrypt/main.c
+++ b/dlls/ncrypt/main.c
@@ -23,6 +23,7 @@
 #include "windef.h"
 #include "winbase.h"
 #include "ncrypt.h"
+#include "ncrypt_internal.h"
 #include "wine/debug.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(ncrypt);
@@ -129,10 +130,23 @@ SECURITY_STATUS WINAPI NCryptOpenKey(NCRYPT_PROV_HANDLE provider, NCRYPT_KEY_HAN
     return NTE_NOT_SUPPORTED;
 }
 
+int allocate_storage_provider_object(struct ncrypt_object **providerobject)
+{
+    *providerobject = malloc(sizeof(struct ncrypt_object));
+    if (providerobject == NULL)
+    {
+        ERR("Error allocating memory.\n");
+        return NTE_NO_MEMORY;
+    }
+    memset(*providerobject, 0, sizeof(struct ncrypt_object));
+    (*providerobject)->type = STORAGE_PROVIDER;
+    return ERROR_SUCCESS;
+}
+
 SECURITY_STATUS WINAPI NCryptOpenStorageProvider(NCRYPT_PROV_HANDLE *provider, const WCHAR *name, DWORD flags)
 {
     FIXME("(%p, %s, %u): stub\n", provider, wine_dbgstr_w(name), flags);
-    return NTE_NOT_SUPPORTED;
+    return allocate_storage_provider_object(provider);
 }
 
 SECURITY_STATUS WINAPI NCryptSetProperty(NCRYPT_HANDLE object, const WCHAR *property,
diff --git a/dlls/ncrypt/ncrypt_internal.h b/dlls/ncrypt/ncrypt_internal.h
new file mode 100644
index 00000000000..1201cdd857a
--- /dev/null
+++ b/dlls/ncrypt/ncrypt_internal.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2021 Santino Mazza
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef NCRYPT_INTERNAL_H
+#define NCRYPT_INTERNAL_H
+
+#include <stdarg.h>
+
+#include "windef.h"
+#include "winbase.h"
+#include "winternl.h"
+
+struct ncrypt_storage_provider_object
+{
+    // FIXME Stub
+};
+
+enum ncrypt_object_type
+{
+    STORAGE_PROVIDER,
+};
+
+struct ncrypt_object_property
+{
+    WCHAR *key;
+    DWORD value_size;
+    VOID *value;
+};
+
+struct ncrypt_object
+{
+    enum ncrypt_object_type type;
+    DWORD number_of_properties;
+    struct ncrypt_object_property *properties;
+    union
+    {
+        struct ncrypt_storage_provider_object storage_provider;
+    } object;
+};
+
+#endif // NCRYPT_INTERNAL_H
diff --git a/dlls/ncrypt/tests/ncrypt.c b/dlls/ncrypt/tests/ncrypt.c
index b948665ebaa..76e5396b288 100644
--- a/dlls/ncrypt/tests/ncrypt.c
+++ b/dlls/ncrypt/tests/ncrypt.c
@@ -86,11 +86,11 @@ UCHAR invalid_rsa_key_blob[] = {
 
 static void test_key_import_rsa(void)
 {
-    todo_wine {
     NCRYPT_PROV_HANDLE prov;
     SECURITY_STATUS ret = NCryptOpenStorageProvider(&prov, NULL, 0);
     ok(ret == ERROR_SUCCESS, "got 0x%x\n", ret);
 
+    todo_wine {
     NCRYPT_KEY_HANDLE key = NULL;
     ret = NCryptImportKey(prov, NULL, BCRYPT_RSAPUBLIC_BLOB, NULL, &key, rsa_key_blob, sizeof(rsa_key_blob), 0);
     ok(ret == ERROR_SUCCESS, "got 0x%x\n", ret);
-- 
2.32.0




More information about the wine-devel mailing list