ncrypt: Make NCryptOpenStorageProvider return a valid stub pointer.

Some applications crash when the storage provider is null.

Signed-off-by: Santino Mazza <mazzasantino1206@gmail.com>
Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Santino Mazza 2022-02-16 15:13:04 +01:00 committed by Alexandre Julliard
parent 631fde70b8
commit cf3517b790
3 changed files with 64 additions and 3 deletions

View File

@ -19,10 +19,12 @@
*/
#include <stdarg.h>
#include <stdlib.h>
#include "windef.h"
#include "winbase.h"
#include "ncrypt.h"
#include "ncrypt_internal.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(ncrypt);
@ -99,6 +101,14 @@ SECURITY_STATUS WINAPI NCryptGetProperty(NCRYPT_HANDLE object, const WCHAR *prop
return NTE_NOT_SUPPORTED;
}
static struct object *allocate_object(enum object_type type)
{
struct object *ret;
if (!(ret = calloc(1, sizeof(*ret)))) return NULL;
ret->type = type;
return ret;
}
SECURITY_STATUS WINAPI NCryptImportKey(NCRYPT_PROV_HANDLE provider, NCRYPT_KEY_HANDLE decrypt_key,
const WCHAR *type, NCryptBufferDesc *params, NCRYPT_KEY_HANDLE *key,
PBYTE data, DWORD datasize, DWORD flags)
@ -131,8 +141,17 @@ SECURITY_STATUS WINAPI NCryptOpenKey(NCRYPT_PROV_HANDLE provider, NCRYPT_KEY_HAN
SECURITY_STATUS WINAPI NCryptOpenStorageProvider(NCRYPT_PROV_HANDLE *provider, const WCHAR *name, DWORD flags)
{
struct object *object;
FIXME("(%p, %s, %u): stub\n", provider, wine_dbgstr_w(name), flags);
return NTE_NOT_SUPPORTED;
if (!(object = allocate_object(STORAGE_PROVIDER)))
{
ERR("Error allocating memory.\n");
return NTE_NO_MEMORY;
}
*provider = (NCRYPT_PROV_HANDLE)object;
return ERROR_SUCCESS;
}
SECURITY_STATUS WINAPI NCryptSetProperty(NCRYPT_HANDLE object, const WCHAR *property,

View File

@ -0,0 +1,44 @@
/*
* 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
*/
struct storage_provider
{
};
enum object_type
{
STORAGE_PROVIDER,
};
struct object_property
{
WCHAR *key;
DWORD value_size;
void *value;
};
struct object
{
enum object_type type;
DWORD num_properties;
struct object_property *properties;
union
{
struct storage_provider storage_provider;
};
};

View File

@ -92,12 +92,10 @@ static void test_key_import_rsa(void)
NCRYPT_KEY_HANDLE key;
SECURITY_STATUS ret;
todo_wine {
prov = 0;
ret = NCryptOpenStorageProvider(&prov, NULL, 0);
ok(ret == ERROR_SUCCESS, "got %#lx\n", ret);
ok(prov, "got null handle\n");
}
todo_wine {
key = 0;