Skip to content

toke.l: check the whole argument regex in strict mode - #573

Open
Ar-maan05 wants to merge 1 commit into
sudo-project:mainfrom
Ar-maan05:fix-strict-arg-regex
Open

Ar-maan05 wants to merge 1 commit into
sudo-project:mainfrom
Ar-maan05:fix-strict-arg-regex

Conversation

@Ar-maan05

Copy link
Copy Markdown

With an invalid regex in the command arguments, visudo -c says everything is fine:

$ cat bad.sudoers
root ALL = /bin/ls ^[a-z$
root ALL = /bin/cat ^foo(bar$
$ visudo -c -s -f bad.sudoers
bad.sudoers: parsed OK

The same mistake in a command path regex (^/bin/[a-z$) is caught, so it's only the argument case that slips through.

The strict-mode check in the GOTREGEX $ rule compiles sudoerstext, which at that point is just the $ that was matched, so it always passes. The full expression has already been collected in sudoerslval.command.args by fill_args(), so this compiles that instead. toke.c gets the same one-line edit rather than a full regeneration.

After the fix:

$ visudo -c -s -f bad.sudoers
bad.sudoers:1:25: Unmatched [, [^, [:, [., or [=
root ALL = /bin/ls ^[a-z$
                        ^
bad.sudoers:2:29: Unmatched ( or \(
root ALL = /bin/cat ^foo(bar$
                            ^

Valid argument regexes (/bin/ls ^[a-z]+$) still parse OK, and make -C plugins/sudoers check passes.

When a command's arguments are a regular expression (^...$), the GOTREGEX "$" rule validated sudoerstext in strict mode, which at that point is only the "$" that was just matched, not the expression collected in sudoerslval.command.args. As a result, visudo -c accepted invalid argument regexes such as "/bin/ls ^[a-z$", while the same mistake in a command path regex was reported.

Compile the accumulated arguments instead.
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.

1 participant