Skip to content

fix: Three bug fixes — sys.path timing, module collision, eval() security#5

Merged
haugoug merged 1 commit intogvsoc:mainfrom
germainh512:bugfixes
Mar 9, 2026
Merged

fix: Three bug fixes — sys.path timing, module collision, eval() security#5
haugoug merged 1 commit intogvsoc:mainfrom
germainh512:bugfixes

Conversation

@germainh512
Copy link

Fixes

1. testset_build() now runs while python_paths are still in sys.path

Before: testset_build() was called after the finally block restored sys.path, so any imports inside testset_build() from configured gvtest.yaml paths would fail with ImportError.

After: testset_build() runs inside the try block 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 in sys.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() with ast.literal_eval() in Target

Before: get_sourceme() and get_envvars() used bare eval() 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.

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).
@haugoug haugoug merged commit fb66d43 into gvsoc:main Mar 9, 2026
3 checks passed
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.

2 participants