You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
REDIRECTION_TOKENS mutated by alias/macro create+list (4 locations) -- compounding cross-instance state corruption #1649
Hi cmd2 team — found a module-level state mutation bug in cmd2/cmd2.py while running adversarial test generation via tailtest. One root cause, four copy-pasted source locations, compounding effect across calls.
Bug
Four functions assign constants.REDIRECTION_TOKENS by reference then .extend() it with terminators:
Function
Line
_alias_create
3821
_alias_list
3901
_macro_create
4068
_macro_list
4191
Each is shaped like:
tokens_to_unquote=constants.REDIRECTION_TOKENS# reference, not copytokens_to_unquote.extend(self.statement_parser.terminators)
Every call to these four functions permanently appends terminators to the module-level constants.REDIRECTION_TOKENS. Over multiple calls the list grows without bound:
After 0 calls: ['|', '>', '>>']
After 1 call: ['|', '>', '>>', ';']
After 5 calls: ['|', '>', '>>', ';', ';', ';', ';', ';', ';', ';', ';']
Impact
Compounding mutation: Each alias/macro create/list call pollutes the global list.
Cross-instance corruption: Two Cmd() instances in the same process share the corrupted state. Instance A's alias operations affect instance B's redirection parsing.
Unbounded growth in long-running sessions: Each invocation adds duplicates.
@pramodavansaber Thank you for your well-written bug report! As you said, its a 4-line change, we should be able to incorporate a fix into an upcoming PR that we are working on.
Activity
tleonhardt commentedon Apr 24, 2026
@pramodavansaber Thank you for your well-written bug report! As you said, its a 4-line change, we should be able to incorporate a fix into an upcoming PR that we are working on.
tleonhardt commentedon Apr 24, 2026
#1650 fixes this on the 3.x branch in preparation for a 3.5.1 bug fix release.
We will fix it separately on the
mainbranch to go into 4.0.0.