清理$ PATH以查找-execdir

时间:2017-02-12 08:35:14

标签: bash path find relative-path sanitization

建议{p> find -execdir优先于-exec,说明手册中存在不可避免的安全问题,以及bugs部分中的列表。

man find-execdir

  

如果您使用此选项,则必须确保您的                 $PATH环境变量未引用.;否则,一个                 攻击者可以通过适当的方式运行他们喜欢的任何命令                 您将在其中运行-execdir的目录中的命名文件。相同                 适用于$PATH中的条目为空或哪些条目为空                 绝对目录名称。

bash脚本中,如何遵守手册"必须"并删除$PATH中的所有相对或空元素?

1 个答案:

答案 0 :(得分:1)

您可以使用以下bash函数清理searchbar.addEventListener('keypress', function(e) { //filter with keypress - without enter //filter function - on "chan" array var filterItems = function(query) { return chan.filter(function(el) { return el.toLowerCase().indexOf(query.toLowerCase()) <= -1; }); }; //searchquery var searchQuery = document.getElementById('searchbar').value; //declare a var for array of items to be filtered var filtered = filterItems(searchQuery); console.log(searchQuery); console.log(filtered); console.log(chan); //if searchbar is blank and there is a keypress after it //shows all elements according to the original chan array //else disables elements according to filtered array if (searchQuery === "") { for (let i = 0; i < chan.length; i++) { document.getElementById(chan[i]).style.display = "block"; } } else { for (let i = 0; i < filtered.length; i++) { document.getElementById(filtered[i]).style.display = "none"; } } filtered = chan; }

PATH

测试:

sanitize_PATH()
{
    local new_path=""
    local dir
    while read -r -d: dir
    do
        if [[ $dir == /* ]]
        then
            new_path="$new_path:$dir"
        else
            echo "dropping from PATH: '$dir'"
        fi
    done <<< "$PATH:"
    PATH="${new_path#:}"
    echo PATH="$PATH"
}