How do I set the taint mode in a perl script with a '#!/usr/bin/env perl'- shebang?

前端 未结 2 922
挽巷
挽巷 2021-02-05 21:55

how do I set the taint mode in a perl script with a

#!/usr/bin/env perl

shebang?

2条回答
  •  既然无缘
    2021-02-05 22:43

    You can pass the PERL5OPT environment variable on the shebang line:

    #!/usr/bin/env PERL5OPT=-T perl
    

    This seems all rather backwards to me.

    Another option, is to re-execute the script under taint mode if you detect it's not on:

    #!/usr/bin/env perl
    
    warn 'Taint mode is '.(${^TAINT} ? 'on' : 'off'); # For debugging
    
    exec($^X,'-T',$0,@ARGV) unless ${^TAINT};
    
    # do stuff under taint mode here
    

    Obviously, this is a major startup performance hit.

提交回复
热议问题