Skip to content

list: fix anonymous section becoming named on type change - #27

Open
plistiak wants to merge 1 commit into
openwrt:masterfrom
plistiak:fix-anonymous-section
Open

plistiak wants to merge 1 commit into
openwrt:masterfrom
plistiak:fix-anonymous-section

Conversation

@plistiak

Copy link
Copy Markdown

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 whole
uci_section. The new section gets the old generated cfg... name, but the
anonymous 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->anonymous when the section is reallocated and
adds 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:

  • anonymous section, different-length type change
  • anonymous section, same-length type change
  • named section type change
  • explicit rename of an anonymous section

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>
@plistiak plistiak changed the title list: preserve anonymous flag on type change list: fix anonymous section becoming named on type change Sep 24, 2026
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.

1 participant