From 47d4097efaa616452c10b708d878136fa3528c8e Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Thu, 21 Sep 2023 16:49:11 +0200 Subject: [PATCH] vkd3d-utils: Check for a NULL 'blob' pointer in D3DCreateBlob(). --- libs/vkd3d-utils/vkd3d_utils_main.c | 6 ++++++ libs/vkd3d-utils/vkd3d_utils_private.h | 4 ++++ tests/hlsl_d3d12.c | 24 ++++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/libs/vkd3d-utils/vkd3d_utils_main.c b/libs/vkd3d-utils/vkd3d_utils_main.c index b0c025f4..e7985e3c 100644 --- a/libs/vkd3d-utils/vkd3d_utils_main.c +++ b/libs/vkd3d-utils/vkd3d_utils_main.c @@ -537,6 +537,12 @@ HRESULT WINAPI D3DCreateBlob(SIZE_T data_size, ID3DBlob **blob) TRACE("data_size %lu, blob %p.\n", data_size, blob); + if (!blob) + { + WARN("Invalid 'blob' pointer specified.\n"); + return D3DERR_INVALIDCALL; + } + if (!(data = vkd3d_calloc(data_size, 1))) return E_OUTOFMEMORY; diff --git a/libs/vkd3d-utils/vkd3d_utils_private.h b/libs/vkd3d-utils/vkd3d_utils_private.h index 1b8254b6..e0a697de 100644 --- a/libs/vkd3d-utils/vkd3d_utils_private.h +++ b/libs/vkd3d-utils/vkd3d_utils_private.h @@ -31,4 +31,8 @@ #include "vkd3d_memory.h" #include +#ifndef D3DERR_INVALIDCALL +#define D3DERR_INVALIDCALL _HRESULT_TYPEDEF_(0x8876086c) +#endif + #endif /* __VKD3D_UTILS_PRIVATE_H */ diff --git a/tests/hlsl_d3d12.c b/tests/hlsl_d3d12.c index ff29f1f7..de3737f6 100644 --- a/tests/hlsl_d3d12.c +++ b/tests/hlsl_d3d12.c @@ -20,6 +20,10 @@ #include "d3d12_crosstest.h" #include "vkd3d_common.h" +#ifndef D3DERR_INVALIDCALL +#define D3DERR_INVALIDCALL 0x8876086c +#endif + struct test_options test_options = {0}; #define check_preprocess(a, b, c, d, e) check_preprocess_(__LINE__, a, b, c, d, e) @@ -602,6 +606,25 @@ static void test_thread_id(void) destroy_test_context(&context); } +static void test_create_blob(void) +{ + unsigned int refcount; + ID3D10Blob *blob; + HRESULT hr; + + hr = D3DCreateBlob(1, NULL); + ok(hr == D3DERR_INVALIDCALL, "Got hr %#x.\n", hr); + + hr = D3DCreateBlob(0, NULL); + ok(hr == D3DERR_INVALIDCALL, "Got hr %#x.\n", hr); + + hr = D3DCreateBlob(0, &blob); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + refcount = ID3D10Blob_Release(blob); + ok(!refcount, "Got refcount %u.\n", refcount); +} + START_TEST(hlsl_d3d12) { parse_args(argc, argv); @@ -610,4 +633,5 @@ START_TEST(hlsl_d3d12) run_test(test_preprocess); run_test(test_thread_id); + run_test(test_create_blob); }