Skip to content

Commit 2741d83

Browse files
jwinarskeandywolff
andauthored
Fix StrcmpFixed matching prefixes in the Vulkan embedder tests (flutter#192999)
`StrcmpFixed` compares `N - 1` bytes, which stops at the literal's last character, so it matches any name the literal is a prefix of. `"vkQueueSubmit"` also claims `"vkQueueSubmit2"`, and the test hands back a `vkQueueSubmit` wrapper for it. Nothing in tree resolves both today, so this is latent. A dispatcher that does gets a function with the wrong signature called with `vkQueueSubmit2` arguments, and segfaults in the driver. Impeller's dispatcher resolves both — that is how I found it. Compare `N` bytes: the terminator is part of the literal, so the match is exact. No new test. The existing swap tests cover it once something resolves both names; adding a test that asserts a helper's byte count is not worth the line. First of six, from flutter#187525. Independent — nothing else in the series depends on it landing first. ## Pre-launch checklist - No API change, no docs affected. - Existing `EmbedderTest.CanSwapOutVulkanCalls` passes (host_debug, Linux/SwiftShader). --------- Co-authored-by: Andy Wolff <[email protected]>
1 parent fcd17d4 commit 2741d83

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

‎engine/src/flutter/shell/platform/embedder/tests/embedder_vk_unittests.cc‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,9 @@ VkResult QueueSubmit(VkQueue queue,
5454
fence);
5555
}
5656

57-
template <size_t N>
58-
int StrcmpFixed(const char* str1, const char (&str2)[N]) {
59-
return strncmp(str1, str2, N - 1);
60-
}
61-
6257
PFN_vkVoidFunction GetDeviceProcAddr(VkDevice device, const char* pName) {
6358
FML_DCHECK(g_vulkan_proc_info.get_device_proc_addr != nullptr);
64-
if (StrcmpFixed(pName, "vkQueueSubmit") == 0) {
59+
if (std::strcmp(pName, "vkQueueSubmit") == 0) {
6560
g_vulkan_proc_info.queue_submit_proc_addr =
6661
reinterpret_cast<decltype(vkQueueSubmit)*>(
6762
g_vulkan_proc_info.get_device_proc_addr(device, pName));
@@ -72,7 +67,7 @@ PFN_vkVoidFunction GetDeviceProcAddr(VkDevice device, const char* pName) {
7267

7368
PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* pName) {
7469
FML_DCHECK(g_vulkan_proc_info.get_instance_proc_addr != nullptr);
75-
if (StrcmpFixed(pName, "vkGetDeviceProcAddr") == 0) {
70+
if (std::strcmp(pName, "vkGetDeviceProcAddr") == 0) {
7671
g_vulkan_proc_info.get_device_proc_addr =
7772
reinterpret_cast<decltype(vkGetDeviceProcAddr)*>(
7873
g_vulkan_proc_info.get_instance_proc_addr(instance, pName));
@@ -108,7 +103,7 @@ TEST_F(EmbedderTest, CanSwapOutVulkanCalls) {
108103
context.SetVulkanInstanceProcAddressCallback(
109104
[](void* user_data, FlutterVulkanInstanceHandle instance,
110105
const char* name) -> void* {
111-
if (StrcmpFixed(name, "vkGetInstanceProcAddr") == 0) {
106+
if (std::strcmp(name, "vkGetInstanceProcAddr") == 0) {
112107
g_vulkan_proc_info.get_instance_proc_addr =
113108
reinterpret_cast<decltype(vkGetInstanceProcAddr)*>(
114109
EmbedderTestContextVulkan::InstanceProcAddr(user_data,

0 commit comments

Comments
 (0)