fix: Three bug fixes — sys.path timing, module collision, eval() security#5
Merged
haugoug merged 1 commit intogvsoc:mainfrom Mar 9, 2026
Merged
fix: Three bug fixes — sys.path timing, module collision, eval() security#5haugoug merged 1 commit intogvsoc:mainfrom
haugoug merged 1 commit intogvsoc:mainfrom
Conversation
1. testset_build() now runs while python_paths are still in sys.path Previously testset_build() was called after the finally block restored sys.path, so imports inside testset_build() from configured paths would fail with ImportError. 2. Use unique module names per testset file to avoid sys.modules collisions All testset files were loaded as 'module.name', causing them to overwrite each other in sys.modules. Now uses a hash-based unique name. 3. Replace eval() with ast.literal_eval() in Target for security get_sourceme() and get_envvars() used bare eval() which allowed arbitrary code execution from config values. ast.literal_eval() only allows safe Python literals (strings, numbers, tuples, lists, dicts, booleans, None). Added regression tests for all three fixes (116 total tests, all passing).
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.
Fixes
1.
testset_build()now runs whilepython_pathsare still insys.pathBefore:
testset_build()was called after thefinallyblock restoredsys.path, so any imports insidetestset_build()from configuredgvtest.yamlpaths would fail withImportError.After:
testset_build()runs inside thetryblock while paths are still available.2. Unique module names per testset file
Before: All testset files were loaded as
"module.name", causing them to overwrite each other insys.modules. Loading two testsets with different module-level variables could produce wrong results.After: Each testset gets a unique module name based on its file path hash.
3. Replace
eval()withast.literal_eval()in TargetBefore:
get_sourceme()andget_envvars()used bareeval()on config values, allowing arbitrary code execution (e.g.__import__("os").system("rm -rf /")).After: Uses
ast.literal_eval()which only allows safe Python literals.Tests
Added 3 regression tests covering all fixes. 116 total tests, all passing. Real-world testsuite (gvsoc-sdk examples) also verified: 12/12 pass.