Skip to content

Conversation

@steweg
Copy link
Contributor

@steweg steweg commented Sep 28, 2025

This patch fixes the issue if extensions are used within subsequent refine or typedef statements

@steweg steweg force-pushed the bugfix/extention_parents branch from 3fc94e9 to 4c9e18f Compare September 28, 2025 21:20
Copy link
Member

@michalvasko michalvasko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The solution seems a bit like a workaround and I think another solution would be better. The parent can be corrected right when it becomes invalid, which is when the grouping content is being copied into the uses. So the code would go through all the direct substatements of the grouping and correct parents in all the extensions.

I am also wondering about an extension directly under the grouping. If it is copied into the uses, not just the parent should be changed but the parent type as well. Another test for this should be added in any case. Let me know if I should implement all this instead.

@steweg
Copy link
Contributor Author

steweg commented Sep 29, 2025

I think your proposal is not correct. The problem that I was facing was already in parsed tree structure, not in compiled. The pointer of parent is actually corrected exactly after it become invalidated. It become invalidated due to usage of LY_ARRAY on refines and typedefs, which requires usage of LY_ARRAY_NEW, which moves it content in memory without ability to update internally the content of data that are being moved....So if you add first refine with extension. Everything works correct. But immediately if you put another one, that one will invalidate the parent pointer of extension from the previous one. AFAIK there is no other way to tell when the pointer of ext->parent will be invalidated, so not sure how exactly you would like to do it.

The only better solution I can think of would be to change refines and typedefs from LY_ARRAY to linked list, which will not be facing this kind of issue, but that would also mean change of public API, so I didn't went this way.

Feel free to do whatever you think is the best for libyang. As long as my proposed tests will not show any valgrind issues (like invalid read) I am ok with it.

@michalvasko
Copy link
Member

Okay, then I misunderstood the issue and it is simpler than I thought. Please document the actual problem (realloc is causing the pointers to become invalid) and it can be merged, thanks.

This patch fixes the issue if extensions are used within subsequent
refine or typedef statements
@steweg steweg force-pushed the bugfix/extention_parents branch from 4c9e18f to 10f211e Compare September 30, 2025 11:23
@steweg
Copy link
Contributor Author

steweg commented Sep 30, 2025

Not sure if I understood you correctly, I assumed you mean document it directly in the code. So I have extended little bit the comments. Hope it is enough.

@michalvasko
Copy link
Member

Yes, I meant in the code, is fine now.

@michalvasko michalvasko merged commit 4ed27e0 into CESNET:devel Sep 30, 2025
11 checks passed
@steweg steweg deleted the bugfix/extention_parents branch September 30, 2025 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants