Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In what way is `fast_abs_path` "dangerous, but potentially faster"?

Tags:

perl

The documentation for the Cwd module states that fast_abs_path is a "more dangerous, but potentially faster version of abs_path". In what way is it dangerous? Under what circumstances is it faster? Does the behavior vary by platform?

like image 657
Matthew Simoneau Avatar asked May 11 '12 16:05

Matthew Simoneau


1 Answers

fast_abs_path invokes chdir to have the kernel resolve the path leading up to what you passed it all at once, instead of carefully checking each component and building a new path piece by piece; the problem is that it is possible that permissions would prevent it from chdiring back to the original directory afterward. (Some systems can use open and fchdir to get around this, but it's not reliably available on all platforms where Perl runs.)

Whether this can even occur depends on whether it is possible for your script to execute in a directory which it would not be able to access directly. On Unix-like systems this can happen when a setuid wrapper chdirs to a restricted permissions area and then drops the setuid. (Historically the restricted permissions are on a path component named lock; various mail and Usenet news subsystems have used this to protect their queue directories.)

like image 195
geekosaur Avatar answered Nov 03 '22 01:11

geekosaur