scripts: Improve SafePNextCopy for unknown structs#385
Conversation
If a pNext chain contains unknown structure, the current code will skip it by not updating prev_pNext. When a known structure is encountered later, the chain will be re-sewn to exclude the custom structure. However, if the unknown structure is at the very end, the current code will not repair the pNext pointer of prev_pNext. Thus the safe copy of the chain will still contain an unsafe pNext pointer at the end. This commit fixes this issue by setting prev_pNext->pNext on every iteration, even if prev_pNext itself is not updated. If safe_pNext is itself a nullptr, we should still overwrite prev_pNext->pNext so as not to leave an unsafe value there. If later a known structure is seen, this nullptr will be overwritten and the current functionality will remain the same.
| } | ||
| pNext = header->pNext; | ||
| if (prev_pNext && safe_pNext) { | ||
| if (prev_pNext) { |
There was a problem hiding this comment.
this is just the python script, you need to re-generate the code to apply it
|
@spatel2-samsung it would be nice to have a test, which happy to write, could you just provide a small example (pseudocode is fine) of 1 or 2 function calls with their pNext struct that would demonstrate this issue |
The following pseudocode should demonstrate this. The example I used to find the issue isn't exactly this (I didn't test by calling SafePNextCopy directly, I used a debugger during the vkCreateInstance call to see the difference). I can create a full minimal example if that's better! |
|
@spatel2-samsung looks good (and I tested it)
+ // need to make sure pass through a private struct
+ // https://github.com/KhronosGroup/Vulkan-Utility-Libraries/pull/385#issuecomment-4490691826
if (prev_pNext) {
prev_pNext->pNext = (VkBaseOutStructure*)safe_pNext;
}
|
If a pNext chain contains unknown structure, the current code will skip it by not updating prev_pNext. When a known structure is encountered later, the chain will be re-sewn to exclude the custom structure. However, if the unknown structure is at the very end, the current code will not repair the pNext pointer of prev_pNext. Thus the safe copy of the chain will still contain an unsafe pNext pointer at the end.
This commit fixes this issue by setting prev_pNext->pNext on every iteration, even if prev_pNext itself is not updated. If safe_pNext is itself a nullptr, we should still overwrite prev_pNext->pNext so as not to leave an unsafe value there. If later a known structure is seen, this nullptr will be overwritten and the current functionality will remain the same.