Skip to content

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

Merged
millert merged 1 commit into
sudo-project:mainfrom
Ar-maan05:fix-strict-arg-regex
Oct 22, 2026
Merged

millert merged 1 commit into
sudo-project:mainfrom
Ar-maan05:fix-strict-arg-regex

Conversation

@Ar-maan05

Copy link
Copy Markdown
Contributor

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.

@millert millert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, thanks!

@millert
millert merged commit e57adb3 into sudo-project:main Oct 22, 2026
@Ar-maan05
Ar-maan05 deleted the fix-strict-arg-regex branch October 22, 2026 00:20
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