Skip to content

CFE-2663: Select empty region at end of file when select_end_match_eof is set (3.27)#6229

Open
nickanderson wants to merge 5 commits into
cfengine:3.27.xfrom
nickanderson:CFE-2663/3.27.x
Open

CFE-2663: Select empty region at end of file when select_end_match_eof is set (3.27)#6229
nickanderson wants to merge 5 commits into
cfengine:3.27.xfrom
nickanderson:CFE-2663/3.27.x

Conversation

@nickanderson

Copy link
Copy Markdown
Member

When an insert_lines (or other edit_line) promise uses select_region with select_end_match_eof => "true", and the select_start delimiter matches the last line of the file, SelectRegion() rejects the (empty) region at EOF and the edit fails with "could not select an edit region". This makes the final section of an INI-style file impossible to populate once it is empty, which is exactly what set_variable_values_ini() / manage_variable_values_ini() hit in the wild.

Ticket: CFE-2663

An insert_lines promise using select_region with select_end_match_eof
cannot select the region of the final section when that section header
is the last line of the file. The region is empty and sits at the end
of the file, SelectRegion() rejects it, and the insertion fails with
"could not select an edit region".

This test fails today and will pass once SelectRegion() honors
select_end_match_eof for an empty region at end of file.

Ticket: CFE-2663
Changelog: None
Signed-off-by: Nick Anderson <nick@cmdln.org>
(cherry picked from commit ebf30a2)
When select_region matched a start delimiter on the last line of the
file and include_start_delimiter was false, SelectRegion() rejected the
region as an "empty region at the end of file" and the edit failed with
"could not select an edit region". This happened even when
select_end_match_eof was true, which is meant to let the region extend
to the end of the file.

Now the empty region at end of file is accepted when select_end_match_eof
is set, so a trailing section (its header being the last line of the
file) can still be populated by insert_lines and similar promises.

Ticket: CFE-2663
Changelog: Title
Signed-off-by: Nick Anderson <nick@cmdln.org>
(cherry picked from commit c7bcc44)
victormlg and others added 2 commits July 10, 2026 20:11
Signed-off-by: Victor Moene <victor.moene@northern.tech>
(cherry picked from commit ff805dd)
Pulls in the macOS build fixes from ENT-14208: the deprecated readdir_r
use in unix_dir.c (PR cfengine#280) and the switch to __APPLE__ instead of DARWIN
(PR cfengine#281). This unblocks the macOS build for the CFE-2663 backport.

Stops deliberately at the ent-14208 merge, short of the CFE-3629
compiler-flag rework (libntech 257982d). That rework enables
-Wgnu-folding-constant as an error, which breaks the pre-existing VLA in
libpromises/evalfunction.c (char key[key_len]) that master has since
removed but these backport branches still carry.

Ticket: ENT-14208
Changelog: None
Signed-off-by: Nick Anderson <nick@cmdln.org>
While VLAs are supported in C99 and C11, they do pose some portability issues so best to avoid their use.

alloca() allocates on the stack frame and is free'd on exit from the function so essentially equivalent.

Ticket: ENT-14208
Changelog: none
(cherry picked from commit 6e95201)
@nickanderson

Copy link
Copy Markdown
Member Author

@cf-bottom jenkins please

@cf-bottom

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants