Skip to content

Fix code scanning alert no. 71#161

Merged
arvindshmicrosoft merged 1 commit intomainfrom
alert-autofix-71
Mar 24, 2026
Merged

Fix code scanning alert no. 71#161
arvindshmicrosoft merged 1 commit intomainfrom
alert-autofix-71

Conversation

@arvindshmicrosoft
Copy link
Member

@arvindshmicrosoft arvindshmicrosoft commented Mar 24, 2026

Fix for https://github.com/microsoft/SQLCallStackResolver/security/code-scanning/71

In general, to fix a constant condition that is always true/false because of local control-flow, remove the redundant condition and keep only the behavior that always happens when that point in the code is reached. Here, by the time we reach line 238 we are already inside if (!resWasCached) { ... }, and resWasCached is never reassigned, so if (!resWasCached) at line 238 is always true. The intended logic is still to guard the cache write with a check against the current dictionary contents, not to re-check the original resWasCached flag. Therefore, the minimal change is to remove the inner if (!resWasCached) wrapper and let the writer-lock section always run when the outer if (!resWasCached) is taken.

Concretely, in Engine/StackResolver.cs, inside ProcessFrameModuleOffset, replace:

238:                 if (!resWasCached) {    // we only need to add to cache if it was not already cached.
239:                     this.rwLockCachedSymbols.AcquireWriterLock(-1);
240:                     if (!this.cachedSymbols.ContainsKey(symKey)) this.cachedSymbols.Add(symKey, result);
241:                     this.rwLockCachedSymbols.ReleaseWriterLock();
242:                 }

with:

238:                 this.rwLockCachedSymbols.AcquireWriterLock(-1);
239:                 if (!this.cachedSymbols.ContainsKey(symKey)) this.cachedSymbols.Add(symKey, result);
240:                 this.rwLockCachedSymbols.ReleaseWriterLock();

This keeps behavior identical: we still only write to the cache when the original lookup missed (outer if (!resWasCached)), but the inner constant condition is removed. No new methods, imports, or definitions are needed.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@arvindshmicrosoft arvindshmicrosoft marked this pull request as ready for review March 24, 2026 04:53
@arvindshmicrosoft arvindshmicrosoft changed the title Potential fix for code scanning alert no. 71: Constant condition Fix code scanning alert no. 71 Mar 24, 2026
@arvindshmicrosoft arvindshmicrosoft merged commit 57eaae4 into main Mar 24, 2026
5 checks passed
@arvindshmicrosoft arvindshmicrosoft deleted the alert-autofix-71 branch March 24, 2026 14:53
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