Skip to content

Commit

Permalink
Disallow parsing 'and' and 'or' as commands
Browse files Browse the repository at this point in the history
Except for and --help and or --help

Fixes #6089
  • Loading branch information
ridiculousfish committed Sep 8, 2019
1 parent fa6bac1 commit e79df33
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/parse_productions.cpp
Expand Up @@ -314,6 +314,14 @@ RESOLVE(block_header) {
}

RESOLVE(decorated_statement) {
// and/or are typically parsed in job_conjunction at the beginning of a job
// However they may be reached here through e.g. true && and false.
// Refuse to parse them as a command except for --help. See #6089.
if ((token1.keyword == parse_keyword_and || token1.keyword == parse_keyword_or) &&
!token2.is_help_argument) {
return NO_PRODUCTION;
}

// If this is e.g. 'command --help' then the command is 'command' and not a decoration. If the
// second token is not a string, then this is a naked 'command' and we should execute it as
// undecorated.
Expand Down
1 change: 1 addition & 0 deletions src/parse_tree.cpp
Expand Up @@ -156,6 +156,7 @@ static wcstring token_type_user_presentable_description(

switch (type) {
// Hackish. We only support the following types.
case symbol_decorated_statement:
case symbol_statement:
return L"a command";
case symbol_argument:
Expand Down

0 comments on commit e79df33

Please sign in to comment.