Skip to content

Commit 0a278cc

Browse files
Check return value of copy_surface_create_info
Not propagating the error code meant that unknown structs in the pNext chains of surface create info structs caused crashes later that should have been prevented. This also allows Out Of Memory conditions to be propagated correctly
1 parent 74047e4 commit 0a278cc

File tree

1 file changed

+65
-26
lines changed

1 file changed

+65
-26
lines changed

loader/wsi.c

Lines changed: 65 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -841,8 +841,11 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateWin32SurfaceKHR(VkInstance insta
841841
const struct loader_struct_type_info ci_types[] = {
842842
{VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR, sizeof(VkWin32SurfaceCreateInfoKHR)},
843843
};
844-
copy_surface_create_info(loader_inst, icd_surface, pCreateInfo, sizeof(ci_types) / sizeof(ci_types[0]), ci_types,
845-
"VkWin32SurfaceCreateInfoKHR", pAllocator);
844+
result = copy_surface_create_info(loader_inst, icd_surface, pCreateInfo, sizeof(ci_types) / sizeof(ci_types[0]), ci_types,
845+
"VkWin32SurfaceCreateInfoKHR", pAllocator);
846+
if (VK_SUCCESS != result) {
847+
goto out;
848+
}
846849

847850
*pSurface = (VkSurfaceKHR)(uintptr_t)icd_surface;
848851

@@ -940,8 +943,11 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateWaylandSurfaceKHR(VkInstance ins
940943
const struct loader_struct_type_info ci_types[] = {
941944
{VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR, sizeof(VkWaylandSurfaceCreateInfoKHR)},
942945
};
943-
copy_surface_create_info(loader_inst, icd_surface, pCreateInfo, sizeof(ci_types) / sizeof(ci_types[0]), ci_types,
944-
"VkWaylandSurfaceCreateInfoKHR", pAllocator);
946+
result = copy_surface_create_info(loader_inst, icd_surface, pCreateInfo, sizeof(ci_types) / sizeof(ci_types[0]), ci_types,
947+
"VkWaylandSurfaceCreateInfoKHR", pAllocator);
948+
if (VK_SUCCESS != result) {
949+
goto out;
950+
}
945951

946952
*pSurface = (VkSurfaceKHR)(uintptr_t)icd_surface;
947953

@@ -1043,8 +1049,11 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateXcbSurfaceKHR(VkInstance instanc
10431049
const struct loader_struct_type_info ci_types[] = {
10441050
{VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR, sizeof(VkXcbSurfaceCreateInfoKHR)},
10451051
};
1046-
copy_surface_create_info(loader_inst, icd_surface, pCreateInfo, sizeof(ci_types) / sizeof(ci_types[0]), ci_types,
1047-
"VkXcbSurfaceCreateInfoKHR", pAllocator);
1052+
result = copy_surface_create_info(loader_inst, icd_surface, pCreateInfo, sizeof(ci_types) / sizeof(ci_types[0]), ci_types,
1053+
"VkXcbSurfaceCreateInfoKHR", pAllocator);
1054+
if (VK_SUCCESS != result) {
1055+
goto out;
1056+
}
10481057

10491058
*pSurface = (VkSurfaceKHR)(uintptr_t)icd_surface;
10501059

@@ -1149,8 +1158,11 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateXlibSurfaceKHR(VkInstance instan
11491158
const struct loader_struct_type_info ci_types[] = {
11501159
{VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR, sizeof(VkXlibSurfaceCreateInfoKHR)},
11511160
};
1152-
copy_surface_create_info(loader_inst, icd_surface, pCreateInfo, sizeof(ci_types) / sizeof(ci_types[0]), ci_types,
1153-
"VkXlibSurfaceCreateInfoKHR", pAllocator);
1161+
result = copy_surface_create_info(loader_inst, icd_surface, pCreateInfo, sizeof(ci_types) / sizeof(ci_types[0]), ci_types,
1162+
"VkXlibSurfaceCreateInfoKHR", pAllocator);
1163+
if (VK_SUCCESS != result) {
1164+
goto out;
1165+
}
11541166

11551167
*pSurface = (VkSurfaceKHR)(uintptr_t)icd_surface;
11561168

@@ -1254,8 +1266,11 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDirectFBSurfaceEXT(VkInstance in
12541266
const struct loader_struct_type_info ci_types[] = {
12551267
{VK_STRUCTURE_TYPE_DIRECTFB_SURFACE_CREATE_INFO_EXT, sizeof(VkDirectFBSurfaceCreateInfoEXT)},
12561268
};
1257-
copy_surface_create_info(loader_inst, icd_surface, pCreateInfo, sizeof(ci_types) / sizeof(ci_types[0]), ci_types,
1258-
"VkDirectFBSurfaceCreateInfoEXT", pAllocator);
1269+
result = copy_surface_create_info(loader_inst, icd_surface, pCreateInfo, sizeof(ci_types) / sizeof(ci_types[0]), ci_types,
1270+
"VkDirectFBSurfaceCreateInfoEXT", pAllocator);
1271+
if (VK_SUCCESS != result) {
1272+
goto out;
1273+
}
12591274

12601275
*pSurface = (VkSurfaceKHR)(uintptr_t)icd_surface;
12611276

@@ -1402,8 +1417,11 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateHeadlessSurfaceEXT(VkInstance in
14021417
const struct loader_struct_type_info ci_types[] = {
14031418
{VK_STRUCTURE_TYPE_HEADLESS_SURFACE_CREATE_INFO_EXT, sizeof(VkHeadlessSurfaceCreateInfoEXT)},
14041419
};
1405-
copy_surface_create_info(loader_inst, icd_surface, pCreateInfo, sizeof(ci_types) / sizeof(ci_types[0]), ci_types,
1406-
"VkHeadlessSurfaceCreateInfoEXT", pAllocator);
1420+
result = copy_surface_create_info(loader_inst, icd_surface, pCreateInfo, sizeof(ci_types) / sizeof(ci_types[0]), ci_types,
1421+
"VkHeadlessSurfaceCreateInfoEXT", pAllocator);
1422+
if (VK_SUCCESS != result) {
1423+
goto out;
1424+
}
14071425

14081426
*pSurface = (VkSurfaceKHR)(uintptr_t)icd_surface;
14091427

@@ -1488,8 +1506,11 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateMacOSSurfaceMVK(VkInstance insta
14881506
const struct loader_struct_type_info ci_types[] = {
14891507
{VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK, sizeof(VkMacOSSurfaceCreateInfoMVK)},
14901508
};
1491-
copy_surface_create_info(loader_inst, icd_surface, pCreateInfo, sizeof(ci_types) / sizeof(ci_types[0]), ci_types,
1492-
"VkMacOSSurfaceCreateInfoMVK", pAllocator);
1509+
result = copy_surface_create_info(loader_inst, icd_surface, pCreateInfo, sizeof(ci_types) / sizeof(ci_types[0]), ci_types,
1510+
"VkMacOSSurfaceCreateInfoMVK", pAllocator);
1511+
if (VK_SUCCESS != result) {
1512+
goto out;
1513+
}
14931514

14941515
*pSurface = (VkSurfaceKHR)(uintptr_t)icd_surface;
14951516

@@ -1599,8 +1620,11 @@ terminator_CreateStreamDescriptorSurfaceGGP(VkInstance instance, const VkStreamD
15991620
const struct loader_struct_type_info ci_types[] = {
16001621
{VK_STRUCTURE_TYPE_STREAM_DESCRIPTOR_SURFACE_CREATE_INFO_GGP, sizeof(VkStreamDescriptorSurfaceCreateInfoGGP)},
16011622
};
1602-
copy_surface_create_info(loader_inst, icd_surface, pCreateInfo, sizeof(ci_types) / sizeof(ci_types[0]), ci_types,
1603-
"VkStreamDescriptorSurfaceCreateInfoGGP", pAllocator);
1623+
result = copy_surface_create_info(loader_inst, icd_surface, pCreateInfo, sizeof(ci_types) / sizeof(ci_types[0]), ci_types,
1624+
"VkStreamDescriptorSurfaceCreateInfoGGP", pAllocator);
1625+
if (VK_SUCCESS != result) {
1626+
goto out;
1627+
}
16041628

16051629
*pSurface = (VkSurfaceKHR)(uintptr_t)icd_surface;
16061630

@@ -1654,8 +1678,11 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateMetalSurfaceEXT(VkInstance insta
16541678
const struct loader_struct_type_info ci_types[] = {
16551679
{VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT, sizeof(VkMetalSurfaceCreateInfoEXT)},
16561680
};
1657-
copy_surface_create_info(loader_inst, icd_surface, pCreateInfo, sizeof(ci_types) / sizeof(ci_types[0]), ci_types,
1658-
"VkMetalSurfaceCreateInfoEXT", pAllocator);
1681+
result = copy_surface_create_info(loader_inst, icd_surface, pCreateInfo, sizeof(ci_types) / sizeof(ci_types[0]), ci_types,
1682+
"VkMetalSurfaceCreateInfoEXT", pAllocator);
1683+
if (VK_SUCCESS != result) {
1684+
goto out;
1685+
}
16591686

16601687
*pSurface = (VkSurfaceKHR)(uintptr_t)icd_surface;
16611688

@@ -1715,8 +1742,11 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateScreenSurfaceQNX(VkInstance inst
17151742
const struct loader_struct_type_info ci_types[] = {
17161743
{VK_STRUCTURE_TYPE_SCREEN_SURFACE_CREATE_INFO_QNX, sizeof(VkScreenSurfaceCreateInfoQNX)},
17171744
};
1718-
copy_surface_create_info(loader_inst, icd_surface, pCreateInfo, sizeof(ci_types) / sizeof(ci_types[0]), ci_types,
1719-
"VkScreenSurfaceCreateInfoQNX", pAllocator);
1745+
result = copy_surface_create_info(loader_inst, icd_surface, pCreateInfo, sizeof(ci_types) / sizeof(ci_types[0]), ci_types,
1746+
"VkScreenSurfaceCreateInfoQNX", pAllocator);
1747+
if (VK_SUCCESS != result) {
1748+
goto out;
1749+
}
17201750

17211751
*pSurface = (VkSurfaceKHR)(uintptr_t)icd_surface;
17221752

@@ -1815,8 +1845,11 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateViSurfaceNN(VkInstance instance,
18151845
const struct loader_struct_type_info ci_types[] = {
18161846
{VK_STRUCTURE_TYPE_VI_SURFACE_CREATE_INFO_NN, sizeof(VkViSurfaceCreateInfoNN)},
18171847
};
1818-
copy_surface_create_info(loader_inst, icd_surface, pCreateInfo, sizeof(ci_types) / sizeof(ci_types[0]), ci_types,
1819-
"VkViSurfaceCreateInfoNN", pAllocator);
1848+
result = copy_surface_create_info(loader_inst, icd_surface, pCreateInfo, sizeof(ci_types) / sizeof(ci_types[0]), ci_types,
1849+
"VkViSurfaceCreateInfoNN", pAllocator);
1850+
if (VK_SUCCESS != result) {
1851+
goto out;
1852+
}
18201853

18211854
*pSurface = (VkSurfaceKHR)(uintptr_t)icd_surface;
18221855

@@ -2129,8 +2162,11 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDisplayPlaneSurfaceKHR(VkInstanc
21292162
{VK_STRUCTURE_TYPE_DISPLAY_SURFACE_CREATE_INFO_KHR, sizeof(VkDisplaySurfaceCreateInfoKHR)},
21302163
{VK_STRUCTURE_TYPE_DISPLAY_SURFACE_STEREO_CREATE_INFO_NV, sizeof(VkDisplaySurfaceStereoCreateInfoNV)},
21312164
};
2132-
copy_surface_create_info(loader_inst, icd_surface, pCreateInfo, sizeof(ci_types) / sizeof(ci_types[0]), ci_types,
2133-
"VkDisplaySurfaceCreateInfoKHR", pAllocator);
2165+
result = copy_surface_create_info(loader_inst, icd_surface, pCreateInfo, sizeof(ci_types) / sizeof(ci_types[0]), ci_types,
2166+
"VkDisplaySurfaceCreateInfoKHR", pAllocator);
2167+
if (VK_SUCCESS != result) {
2168+
goto out;
2169+
}
21342170

21352171
*pSurface = (VkSurfaceKHR)(uintptr_t)icd_surface;
21362172

@@ -2558,8 +2594,11 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateImagePipeSurfaceFUCHSIA(VkInstan
25582594
const struct loader_struct_type_info ci_types[] = {
25592595
{VK_STRUCTURE_TYPE_IMAGEPIPE_SURFACE_CREATE_INFO_FUCHSIA, sizeof(VkImagePipeSurfaceCreateInfoFUCHSIA)},
25602596
};
2561-
copy_surface_create_info(loader_inst, icd_surface, pCreateInfo, sizeof(ci_types) / sizeof(ci_types[0]), ci_types,
2562-
"VkImagePipeSurfaceCreateInfoFUCHSIA", pAllocator);
2597+
result = copy_surface_create_info(loader_inst, icd_surface, pCreateInfo, sizeof(ci_types) / sizeof(ci_types[0]), ci_types,
2598+
"VkImagePipeSurfaceCreateInfoFUCHSIA", pAllocator);
2599+
if (VK_SUCCESS != result) {
2600+
goto out;
2601+
}
25632602

25642603
*pSurface = (VkSurfaceKHR)(uintptr_t)icd_surface;
25652604

0 commit comments

Comments
 (0)