Conversation
When uci_set() changes a section type to a value with a different length, the section is reallocated with uci_alloc_section(). For an anonymous section, the generated section name is passed to the allocator. Since uci_alloc_section() derives the anonymous flag from whether the name is NULL, the newly allocated section becomes named. This causes an anonymous section to be exported with its internal cfg... name and to remain named after the configuration is reloaded. Preserve the anonymous flag of the old section across the reallocation. Add a regression test covering a type change of an anonymous section while preserving its existing options. Signed-off-by: Peter Lištiak <peter@listiak.eu>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While working on another UCI change, I was testing anonymous sections and
noticed that changing a section type could unexpectedly make an anonymous
section become named.
The interesting part is that it only happens when the new section type has
a different length. In that case
uci_set()reallocates the wholeuci_section. The new section gets the old generatedcfg...name, but theanonymous flag is not copied over, so the replacement section becomes
named.
That can later make the internal
cfg...name appear in the config file.This patch preserves
old->anonymouswhen the section is reallocated andadds a regression test for the case.
I found this while working on a separate feature and decided to send it as
a standalone fix because it is unrelated and reproducible on its own.
C is not my primary language, so I used ChatGPT and Claude to help me inspect
the code paths, prepare the regression test and review the patch. I also
verified the behavior and the final change myself.
Tested with: