Skip to content

Fix a module-loading regression that caused an infinite loop#6843

Merged
daxian-dbw merged 3 commits intoPowerShell:masterfrom
daxian-dbw:module
May 10, 2018
Merged

Fix a module-loading regression that caused an infinite loop#6843
daxian-dbw merged 3 commits intoPowerShell:masterfrom
daxian-dbw:module

Conversation

@daxian-dbw
Copy link
Copy Markdown
Member

@daxian-dbw daxian-dbw commented May 8, 2018

PR Summary

Fix #6813

This regression was introduced by #6523, in PSModuleInfo.cs. A circular nested module check was removed because the comment there suggested it happens only with a deprecated workflow module. This causes a StackOverflow exception when running into circular nested modules.

Circular nested modules could happen for a module that is not well structured. For example, the module folder test contains two files: test.psd1 and test.psm1, and test.psd1 has the following content:

@{ ModuleVersion = '0.0.1'; RootModule = 'test'; NestedModules = @('test') }

The same value test is put in both RootModule and NestedModule, which will end up with a module whose nested module points to itself.

There are two changes in this PR:

  1. Add back the circular nested module check in PSModuleInfo.cs.
  2. Remove a wrong Dbg.Assert in ModuleCmdletBase.cs and two checks before it.
    • For the assertion Dbg.Assert(newManifestInfo.SessionState == ss, when facing the example above, the nested module will first be loaded with a different session state, and then when trying to load the root module, the same loaded nested module will be reused for it. So 'newManifestInfo.SessionState' is not ss. The assersion will fail in that case.
    • For the two checks before the assersion, they are not needed anymore based on the comments there.

PR Checklist

Loading
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.

Process is terminating due to StackOverflowException

3 participants