Skip to content

fix(config): return pointers to slice elements in LocalConfig getters#407

Open
Rahulatram321 wants to merge 3 commits into
microcks:masterfrom
Rahulatram321:fix/config-getter-pointer-range
Open

fix(config): return pointers to slice elements in LocalConfig getters#407
Rahulatram321 wants to merge 3 commits into
microcks:masterfrom
Rahulatram321:fix/config-getter-pointer-range

Conversation

@Rahulatram321
Copy link
Copy Markdown

Description

This PR fixes pointer semantics in LocalConfig getters to ensure returned pointers reference real backing slice elements.

Problem

The getters used range-value iteration patterns like:

  • for _, u := range l.Users { return &u }

This returns the address of a loop variable copy, not the original slice element.
As a result, callers mutating through returned pointers may silently modify detached copies, causing subtle state bugs.

Changes

Updated all affected getters in pkg/config/localconfig.go to index-based iteration:

  • GetUser
  • GetServer
  • GetInstance
  • GetAuth

Pattern changed to:

  • for i := range l.Users { return &l.Users[i] } (and equivalent for other slices)

Tests

Added pkg/config/localconfig_test.go with regression coverage that verifies pointer-backed mutation for all four getters:

  • mutate field through returned pointer
  • assert corresponding slice element is updated

Result

  • Getter pointers now correctly point into LocalConfig slices.
  • Prevents stale-copy mutation bugs and makes behavior consistent with caller expectations.

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