如何在污点模式下使用 File::Find::Rule?
我正在尝试使用类似以下内容来获取给定目录中的子目录列表:
#!/usr/bin/perl -wT
use strict;
use warnings;
use File::Find::Rule;
use Data::Dumper;
my @subdirs = File::Find::Rule->maxdepth(1)->directory->relative->in('mydir');
print Dumper(@subdirs);
但是,运行此命令会得到结果:
使用 -T 开关运行时 chdir 中的不安全依赖
我了解 File::Find
有处理污点模式的选项,但我似乎无法在 File::Find::Rule
。 是否可以做到以上几点? 我应该使用替代方法来列出子目录吗? 我是否完全误解了一些我真正应该理解的关于污点模式的明显内容?
I am trying to get a list of subdirectories in a given directory using something like the following:
#!/usr/bin/perl -wT
use strict;
use warnings;
use File::Find::Rule;
use Data::Dumper;
my @subdirs = File::Find::Rule->maxdepth(1)->directory->relative->in('mydir');
print Dumper(@subdirs);
However, running this gives the result:
Insecure dependency in chdir while running with -T switch
I understand that File::Find
has options for dealing with taint mode, but I can’t seem to find an equivalent in File::Find::Rule
. Is it possible to do the above? Should I use an alternative method for listing subdirectories? Am I completely misunderstanding something obvious that I really should understand about taint mode?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
(编辑!)好吧,逻辑表明添加以下
内容会起作用:这使您可以通过将参数直接传递给该模块的
find( )
函数。 顺便说一句,File::Find 提到应该使用qr//
运算符设置$untaint_pattern
。 例如,默认值是但是,这是行不通的! 事实上,您的问题是 File::Find::Rule 中的一个已知错误。 (例如,以下是 CPAN 和 Debian bug 报告。)如果您想要 bug 修复,那么这些错误报告有补丁。
如果您处于受限环境中,您可以做的一件事就是在代码中自己实现补丁。 例如,如果您想将所有内容保留在一个文件中,您可以在
use File::Find::Rule
之后添加下面的大代码块。 请注意,这是一个非常快速的修复,并且可能不是最佳的。 如果它不适合您(例如,因为您的文件名中有空格),请更改使用的模式qr|^([-+@\w./]+)$|
。最后请注意,如果您希望代码组织得更好一点,您可能需要将其转储到一个单独的包中,可能称为 MyFileFindRuleFix 或其他东西,您总是在
File:: 之后
本身。使用
。 Find::Rule(Edit!) Okay, logic would suggest that throwing in the following would work:
This lets you use the taint-mode features of File::Find by passing arguments directly to that module's
find()
function. Incidentally, File::Find mentions that one should set$untaint_pattern
by using theqr//
operator. For example, the default value isHowever, this does not work! In fact, your issue is a known bug in File::Find::Rule. (For example, here are the CPAN and Debian bug reports.) If you would like a bugfix, then both of those bug reports have patches.
If you are in a restricted environment, one thing you can do is essentially implement the patch yourself in your code. For example, if you want to keep everything in one file, you can add the large code block below after
use File::Find::Rule
. Note that this is a very quick fix and may be suboptimal. If it doesn't work for you (e.g., because you have spaces in your filenames), change the patternqr|^([-+@\w./]+)$|
that is used.Note finally that if you want your code organization to be a bit better, you may want to dump this into a separate package, maybe called MyFileFindRuleFix or something, that you always
use
afterFile::Find::Rule
itself.