Fix recursive env var expansion in EnvVars.resolve() (JENKINS-33239)#26248
Open
meetgoti07 wants to merge 5 commits intojenkinsci:masterfrom
Open
Fix recursive env var expansion in EnvVars.resolve() (JENKINS-33239)#26248meetgoti07 wants to merge 5 commits intojenkinsci:masterfrom
meetgoti07 wants to merge 5 commits intojenkinsci:masterfrom
Conversation
When resolving env vars, the value of a variable was expanded using the same map as the resolver. Self-references (e.g. PATH=path1:/Users/meetgoti/GSOC26/.direnv/python-3.10/bin:/Users/meetgoti/.pyenv/plugins/pyenv-virtualenv/shims:/Users/meetgoti/.pyenv/shims:/Users/meetgoti/.pyenv/bin:/opt/apache-maven/bin:/Library/Java/JavaVirtualMachines/temurin-21.jdk/Contents/Home/bin:/Users/meetgoti/.antigravity/antigravity/bin:/opt/homebrew/opt/bison/bin:/opt/homebrew/opt/flex/bin:/opt/homebrew/opt/openjdk/bin:/Users/meetgoti/.nvm/versions/node/v24.11.1/bin:/Users/meetgoti/.cursor/extensions/vadimcn.vscode-lldb-1.12.0/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/pmk/env/global/bin:/Library/Apple/usr/bin:/Library/TeX/texbin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Users/meetgoti/.cursor/extensions/vadimcn.vscode-lldb-1.12.0/bin:/Users/meetgoti/.pyenv/plugins/pyenv-virtualenv/shims:/Users/meetgoti/.pyenv/bin:/opt/apache-maven/bin:/Library/Java/JavaVirtualMachines/temurin-21.jdk/Contents/Home/bin:/Users/meetgoti/.antigravity/antigravity/bin:/opt/homebrew/opt/bison/bin:/opt/homebrew/opt/flex/bin:/Users/meetgoti/.local/bin:/opt/homebrew/opt/openjdk/bin:/opt/homebrew/Caskroom/miniconda/base/bin:/opt/homebrew/Caskroom/miniconda/base/condabin:/Users/meetgoti/Library/pnpm:/Users/meetgoti/.nvm/versions/node/v24.11.1/bin:/Users/meetgoti/.cargo/bin:/opt/homebrew/share/google-cloud-sdk/bin:/Users/meetgoti/go/bin:/opt/homebrew/share/google-cloud-sdk/bin:/Users/meetgoti/go/bin or LD_LIBRARY_PATH=/lib:) could then be expanded repeatedly and cause unbounded growth / OOM. Exclude the variable being expanded from the resolver so self-references are left as literal and no longer expand recursively.
The [testUrlCheck](cci:1://file:///Users/meetgoti/GSOC26/jenkins/core/src/test/java/hudson/util/FormValidationTest.java:123:4-142:5) test was failing intermittently because it made a real network request to `https://www.jenkins.io/`, causing build failures when the external site was unavailable (e.g., 503 Service Unavailable). This change refactors the test to use a mock response for the `open()` method, ensuring the test validates the logic independently of external network conditions.
Author
|
@MarkEWaite, when you have time, could you please review this PR? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix recursive env var expansion and flaky FormValidationTest
Exclude the variable being expanded from the resolver so self-references are left as literal and no longer expand recursively.
Also fixed
FormValidationTest.testUrlCheckto mock the network call tojenkins.io, preventing flaky failures when the external site is unavailable (503 errors).Fixes: #21801
Testing done
Reverted the fix and ran EnvVarsTest#resolveSelfReferenceDoesNotGrowUnbounded to confirm failure (wrong resolved value). Restored the fix and re-ran the test to confirm pass. Added resolveSelfReferenceDoesNotGrowUnbounded in EnvVarsTest and replaceMacroSelfReferenceDoesNotGrowUnbounded in UtilTest; both are executed by the PR build.
Verified
FormValidationTest.testUrlCheckpasses consistently with the new mock implementation.Screenshots (UI changes only)
N/A (core env resolution only).
Before (test output without fix)
After (test output with fix)
Proposed changelog entries
EnvVars.resolve()(e.g.PATH=path1:$PATH,LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH) so values no longer grow unbounded and cause OOM.Proposed changelog category
/label bug
Proposed upgrade guidelines
N/A
Submitter checklist
@Restrictedor have@since TODOJavadocs, as appropriate.@Deprecated(since = "TODO")or@Deprecated(forRemoval = true, since = "TODO"), if applicable.evalto ease future introduction of Content Security Policy (CSP) directives (see documentation).Desired reviewers
@MarkEWaite
Before the changes are marked as
ready-for-merge:Maintainer checklist
upgrade-guide-neededlabel is set and there is a Proposed upgrade guidelines section in the pull request title (see example).lts-candidateto be considered.