Santino Mazza : ncrypt: Validate existence of property before creating one.
Alexandre Julliard
julliard at winehq.org
Mon Feb 21 16:15:14 CST 2022
Module: wine
Branch: master
Commit: e08c2f35f8c8a1a9947b13bb1a696a918c665868
URL: https://source.winehq.org/git/wine.git/?a=commit;h=e08c2f35f8c8a1a9947b13bb1a696a918c665868
Author: Santino Mazza <mazzasantino1206 at gmail.com>
Date: Mon Feb 21 12:13:41 2022 +0100
ncrypt: Validate existence of property before creating one.
Signed-off-by: Santino Mazza <mazzasantino1206 at gmail.com>
Signed-off-by: Hans Leidekker <hans at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/ncrypt/main.c | 27 +++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/dlls/ncrypt/main.c b/dlls/ncrypt/main.c
index 4f9a2f357bd..f8ae2d7a796 100644
--- a/dlls/ncrypt/main.c
+++ b/dlls/ncrypt/main.c
@@ -144,12 +144,12 @@ SECURITY_STATUS WINAPI NCryptFreeObject(NCRYPT_HANDLE handle)
return ret;
}
-static const struct object_property *get_object_property(struct object *object, const WCHAR *name)
+static struct object_property *get_object_property(struct object *object, const WCHAR *name)
{
unsigned int i;
for (i = 0; i < object->num_properties; i++)
{
- const struct object_property *property = &object->properties[i];
+ struct object_property *property = &object->properties[i];
if (!lstrcmpW(property->key, name)) return property;
}
return NULL;
@@ -181,17 +181,16 @@ static struct object *allocate_object(enum object_type type)
return ret;
}
-static SECURITY_STATUS set_object_property(struct object *object, const WCHAR *name, BYTE *value, DWORD value_size)
+struct object_property *add_object_property(struct object *object, const WCHAR *name)
{
struct object_property *property;
- FIXME("check duplicates\n");
if (!object->num_properties)
{
if (!(object->properties = malloc(sizeof(*property))))
{
ERR("Error allocating memory.\n");
- return NTE_NO_MEMORY;
+ return NULL;
}
property = &object->properties[object->num_properties++];
}
@@ -201,7 +200,7 @@ static SECURITY_STATUS set_object_property(struct object *object, const WCHAR *n
if (!(tmp = realloc(object->properties, sizeof(*property) * (object->num_properties + 1))))
{
ERR("Error allocating memory.\n");
- return NTE_NO_MEMORY;
+ return NULL;
}
object->properties = tmp;
property = &object->properties[object->num_properties++];
@@ -211,12 +210,22 @@ static SECURITY_STATUS set_object_property(struct object *object, const WCHAR *n
if (!(property->key = malloc((lstrlenW(name) + 1) * sizeof(WCHAR))))
{
ERR("Error allocating memory.\n");
- return NTE_NO_MEMORY;
+ return NULL;
}
lstrcpyW(property->key, name);
+ return property;
+}
+
+static SECURITY_STATUS set_object_property(struct object *object, const WCHAR *name, BYTE *value, DWORD value_size)
+{
+ struct object_property *property = get_object_property(object, name);
+ void *tmp;
+
+ if (!property && !(property = add_object_property(object, name))) return NTE_NO_MEMORY;
+
property->value_size = value_size;
- if (!(property->value = malloc(value_size)))
+ if (!(tmp = realloc(property->value, value_size)))
{
ERR("Error allocating memory.\n");
free(property->key);
@@ -224,7 +233,9 @@ static SECURITY_STATUS set_object_property(struct object *object, const WCHAR *n
return NTE_NO_MEMORY;
}
+ property->value = tmp;
memcpy(property->value, value, value_size);
+
return ERROR_SUCCESS;
}
More information about the wine-cvs
mailing list