Skip to content

Commit d745850

Browse files
aizu-mcharles-lunarg
authored andcommitted
null-terminate registry value in windows_get_device_registry_entry
1 parent ef26bc7 commit d745850

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

loader/loader_windows.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ VkResult windows_get_device_registry_entry(const struct loader_instance *inst, s
171171
goto out;
172172
}
173173

174-
manifest_path = loader_instance_heap_alloc(inst, requiredSize, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
174+
// Registry string values are not guaranteed to be stored with a terminating null (see RegQueryValueEx). Reserve two
175+
// extra bytes so the value can be terminated after it is read, before it is walked with strlen below.
176+
manifest_path = loader_instance_heap_alloc(inst, requiredSize + 2, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
175177
if (manifest_path == NULL) {
176178
loader_log(inst, VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_DRIVER_BIT, 0,
177179
"windows_get_device_registry_entry: Failed to allocate space for DriverName.");
@@ -195,6 +197,11 @@ VkResult windows_get_device_registry_entry(const struct loader_instance *inst, s
195197
goto out;
196198
}
197199

200+
// requiredSize now holds the number of bytes RegQueryValueEx wrote, which is at most the size queried for the
201+
// allocation, so the two terminators always fit. This keeps the strlen walk in windows_add_json_entry in bounds.
202+
manifest_path[requiredSize] = '\0';
203+
manifest_path[requiredSize + 1] = '\0';
204+
198205
res = windows_add_json_entry(inst, search_paths, value_name, data_type, manifest_path, requiredSize);
199206

200207
out:

0 commit comments

Comments
 (0)