@@ -721,80 +721,64 @@ fn test_env_with_empty_executable_double_quotes() {
721721 . stderr_is ( "env: '': No such file or directory\n " ) ;
722722}
723723
724+ // Our coreutils does not dispatch at Linux for security
724725#[ test]
725- #[ cfg( all ( unix, feature = "dirname" , feature = "echo" ) ) ]
726+ #[ cfg( unix) ]
726727fn test_env_overwrite_arg0 ( ) {
727728 let ts = TestScenario :: new ( util_name ! ( ) ) ;
728729
729- let bin = ts. bin_path . clone ( ) ;
730-
731730 ts. ucmd ( )
732- . args ( & [ "--argv0" , "echo" ] )
733- . arg ( & bin)
734- . args ( & [ "-n" , "hello" , "world!" ] )
731+ . args ( & [ "--argv0" , "hijacked" , "sh" , "-c" , "echo $0" ] )
735732 . succeeds ( )
736- . stdout_is ( "hello world!" )
737- . stderr_is ( "" ) ;
738-
739- ts. ucmd ( )
740- . args ( & [ "-a" , "dirname" ] )
741- . arg ( bin)
742- . args ( & [ "aa/bb/cc" ] )
743- . succeeds ( )
744- . stdout_is ( "aa/bb\n " )
733+ . stdout_is ( "hijacked\n " )
745734 . stderr_is ( "" ) ;
746735}
747736
737+ // Our coreutils does not dispatch at Linux for security
748738#[ test]
749- #[ cfg( all ( unix, feature = "echo" ) ) ]
739+ #[ cfg( unix) ]
750740fn test_env_arg_argv0_overwrite ( ) {
751741 let ts = TestScenario :: new ( util_name ! ( ) ) ;
752742
753- let bin = & ts. bin_path ;
754-
755743 // overwrite --argv0 by --argv0
756744 ts. ucmd ( )
757745 . args ( & [ "--argv0" , "dirname" ] )
758- . args ( & [ "--argv0" , "echo" ] )
759- . arg ( bin)
760- . args ( & [ "aa/bb/cc" ] )
746+ . args ( & [ "--argv0" , "hijacked" , "sh" , "-c" , "echo $0" ] )
761747 . succeeds ( )
762- . stdout_is ( "aa/bb/cc \n " )
748+ . stdout_is ( "hijacked \n " )
763749 . stderr_is ( "" ) ;
764750
765751 // overwrite -a by -a
766752 ts. ucmd ( )
767753 . args ( & [ "-a" , "dirname" ] )
768- . args ( & [ "-a" , "echo" ] )
769- . arg ( bin)
770- . args ( & [ "aa/bb/cc" ] )
754+ . args ( & [ "-a" , "hijacked" , "sh" , "-c" , "echo $0" ] )
771755 . succeeds ( )
772- . stdout_is ( "aa/bb/cc \n " )
756+ . stdout_is ( "hijacked \n " )
773757 . stderr_is ( "" ) ;
774758
775759 // overwrite --argv0 by -a
776760 ts. ucmd ( )
777761 . args ( & [ "--argv0" , "dirname" ] )
778- . args ( & [ "-a" , "echo" ] )
779- . arg ( bin)
780- . args ( & [ "aa/bb/cc" ] )
762+ . args ( & [ "-a" , "hijacked" , "sh" , "-c" , "echo $0" ] )
781763 . succeeds ( )
782- . stdout_is ( "aa/bb/cc \n " )
764+ . stdout_is ( "hijacked \n " )
783765 . stderr_is ( "" ) ;
784766
785767 // overwrite -a by --argv0
786768 ts. ucmd ( )
787769 . args ( & [ "-a" , "dirname" ] )
788- . args ( & [ "--argv0" , "echo" ] )
789- . arg ( bin)
790- . args ( & [ "aa/bb/cc" ] )
770+ . args ( & [ "--argv0" , "hijacked" , "sh" , "-c" , "echo $0" ] )
791771 . succeeds ( )
792- . stdout_is ( "aa/bb/cc \n " )
772+ . stdout_is ( "hijacked \n " )
793773 . stderr_is ( "" ) ;
794774}
795775
776+ // Our coreutils does not dispatch at Linux for security
796777#[ test]
797- #[ cfg( all( unix, feature = "echo" ) ) ]
778+ #[ cfg( all(
779+ all( unix, feature = "echo" ) ,
780+ not( any( target_os = "linux" , target_os = "android" ) )
781+ ) ) ]
798782fn test_env_arg_argv0_overwrite_mixed_with_string_args ( ) {
799783 let ts = TestScenario :: new ( util_name ! ( ) ) ;
800784
0 commit comments