外部输入的参数不能直接作为文件路径,防止被恶意攻击,比如构造一个跨目录限制的文件路径../../../etc/passwd或../../boot.ini,或构造一个指向系统关键文件的链接文件symlink("/etc/shadow","tmp/log")。PS "./"表示当前目录,可以不写,"../"表示当前目录的上一级目录,即当前目录的父目录。windows可以用PathCanonicalize检查文件目录是否标准。
PathCanonicalizeA function
Simplifies a path by removing navigation elements such as "." and ".." to produce a direct, well-formed path.
Note Misuse of this function can lead to a buffer overrun. We recommend the use of the safer PathCchCanonicalize or PathCchCanonicalizeEx function in its place.
Syntax
C++复制
BOOL PathCanonicalizeA(
LPSTR pszBuf,
LP