Fix heap corruption in Windows tests.
authorMateusz Przybylski <mprzybyl@google.com>
Thu, 1 Feb 2024 01:18:52 +0000 (17:18 -0800)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Thu, 1 Feb 2024 18:17:37 +0000 (11:17 -0700)
tests/framework/shim/windows_shim.cpp

index 8a896c1eeb4d13a8fc3a61b86c41529453278ef5..10fd0e345da08e3bc9d04e335ae6aab844489989 100644 (file)
@@ -92,9 +92,11 @@ NTSTATUS APIENTRY ShimQueryAdapterInfo(const LoaderQueryAdapterInfo *query_info)
 
     reg_info->status = LOADER_QUERY_REGISTRY_STATUS_SUCCESS;
     if (reg_info->output_value_size == 0) {
-        ULONG size = 2;  // final null terminator
-        for (auto const &path : *paths) size = static_cast<ULONG>(path.length() * sizeof(wchar_t));
-        // size in bytes, so multiply path size by two and add 2 for the null terminator
+        // final null terminator size
+        ULONG size = 2;
+
+        // size is in bytes, so multiply path size + 1 (for null terminator) by size of wchar (basically, 2).
+        for (auto const &path : *paths) size += static_cast<ULONG>((path.length() + 1) * sizeof(wchar_t));
         reg_info->output_value_size = size;
         if (size != 2) {
             // only want to write data if there is path data to write