Skip to content

CFE-4742: Fixed simulate mode reporting both removal and install of the same package - #6332

Open
djbclark wants to merge 2 commits into
cfengine:masterfrom
djbclark:fix/simulate-pkg-mapremove
Open

CFE-4742: Fixed simulate mode reporting both removal and install of the same package#6332
djbclark wants to merge 2 commits into
cfengine:masterfrom
djbclark:fix/simulate-pkg-mapremove

Conversation

@djbclark

Copy link
Copy Markdown

Ticket: https://northerntech.atlassian.net/browse/CFE-4742

In DiffPkgOperations() and ManifestPkgOperations(), inserting an install message into the installed/present map set name_arch to NULL because the map took ownership of it as a key. The MapRemove() call that cancels a previous removal message ran after that, so it looked up a NULL key and matched nothing: a package recorded as removed and then installed was reported as both removed and installed. Moved the cancellation above the code that hands name_arch to the map.

The regression test feeds r,foo,, + i,foo,1.2.3, records to both functions: it fails before the fix and passes after, verified on x86_64 Linux (CI), Ubuntu 24.04 arm64 (dash), and macOS arm64.

AI-assisted. Full disclosure in the ticket: I reviewed the fix's logic with AI guidance and saw no issues, but I cannot personally vouch for the C itself — the correctness case rests on the discriminating regression test and CI above. If that does not meet the bar for human review, closing this is a fine outcome and the documented finding stands.

…ckage

In DiffPkgOperations() and ManifestPkgOperations(), inserting an install
message into the installed/present map set name_arch to NULL because the
map took ownership of it as a key. The MapRemove() call that cancels a
previous removal message ran after that, so it looked up a NULL key and
matched nothing. The cancellation was silently skipped exactly when an
install message had been inserted: a package recorded as removed and
then installed was reported as both removed and installed. In debug
builds a NULL key also fails an assertion in StringHash() once the map
outgrows the array-map stage.

Moved the cancellation above the code that hands name_arch to the map.

Changelog: Title
Ticket: CFE-4742

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
djbclark added a commit to frdminc/tendcf that referenced this pull request Aug 22, 2026
…re#6332)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@larsewi larsewi self-assigned this Aug 23, 2026
@olehermanse
olehermanse requested a review from larsewi August 24, 2026 13:04
@cfengine cfengine deleted a comment from cf-bottom Aug 24, 2026

@larsewi larsewi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The core fix is correct. In both functions MapInsert takes ownership of name_arch followed by setting it to NULL. Hence, the following MapRemove was looking up a NULL key.

Comment thread tests/unit/simulate_mode_test.c Outdated
Comment thread cf-agent/simulate_mode.c
Co-authored-by: Lars Erik Wik <53906608+larsewi@users.noreply.github.com>
@larsewi

larsewi commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Could you please squash the last the last commit? And while you're at it, feel free to add a signed-of-by trailer with git commit --amend -s --no-edit. Thanks 🚀

@larsewi

larsewi commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

@cf-bottom Jenkins please :)

@larsewi larsewi added the cherry-pick? Fixes which may need to be cherry-picked to LTS branches label Aug 25, 2026
@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

cherry-pick? Fixes which may need to be cherry-picked to LTS branches

Development

Successfully merging this pull request may close these issues.

3 participants