File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
test-framework/sudo-compliance-tests/src/sudo Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -185,7 +185,13 @@ impl Token for Command {
185185 // if no arguments are mentioned, anything is allowed
186186 None
187187 } else {
188- if args. last ( ) . map ( |x| -> & str { x } ) == Some ( "\" \" " ) {
188+ if args. first ( ) . is_some_and ( |x| x. starts_with ( '^' ) ) {
189+ // regular expressions are not supported, give an error message. If there is only a
190+ // terminating '$', this is not treated as a malformed regex by millersudo, so we don't
191+ // need to seperately check for that
192+ return Err ( "regular expressions are not supported" . to_string ( ) ) ;
193+ }
194+ if args. last ( ) . is_some_and ( |x| x == "\" \" " ) {
189195 // if the magic "" appears, no (further) arguments are allowed
190196 args. pop ( ) ;
191197 }
@@ -227,6 +233,8 @@ impl Token for SimpleCommand {
227233 return cvt_err ( glob:: Pattern :: new ( & cmd) ) ;
228234 } else if cmd. starts_with ( "sha" ) {
229235 return Err ( "digest specifications are not supported" . to_string ( ) ) ;
236+ } else if cmd. starts_with ( '^' ) {
237+ return Err ( "regular expressions are not supported" . to_string ( ) ) ;
230238 } else if !cmd. starts_with ( '/' ) {
231239 return Err ( "fully qualified path needed" . to_string ( ) ) ;
232240 }
Original file line number Diff line number Diff line change @@ -212,3 +212,12 @@ fn negated_defaults_errors() {
212212 } ;
213213 assert_contains ! ( output. stderr( ) , diagnostic2) ;
214214}
215+
216+ #[ test]
217+ fn regex_not_interpreted_literally ( ) {
218+ let env = Env ( "ALL ALL=(ALL:ALL) NOPASSWD: /bin/echo ^huk$" ) . build ( ) ;
219+
220+ let output = Command :: new ( "sudo" ) . args ( [ "echo" , "^huk$" ] ) . output ( & env) ;
221+
222+ output. assert_exit_code ( 1 ) ;
223+ }
You can’t perform that action at this time.
0 commit comments