Skip to content

这里有BUG,有可能导致死循环 #3

@diamont1001

Description

@diamont1001

https://github.com/shopex/ecshop/blob/725956bfee1ebcdb8b0eae87027b76be9571be1a/upload/includes/lib_main.php#L273

$arr = $GLOBALS['db']->GetAll('SELECT cat_id, cat_name, parent_id, is_show FROM ' . $GLOBALS['yp']->table('category') . 'WHERE is_show=1');

get_parent_cats 这个函数以上读取可用分类的时候,是通过 is_show=1 来读取的,但是如果上层有分类设置为 is_show=0 的话,那么下层的一些商品的详情页在这里读取上层分类数据的时候就会跳不出这个 while(1) 造成死循环了。

临时解决方法参考(标注 // Eric @20210217 的行是添加的):

function get_parent_cats($cat)
{
    if ($cat == 0)
    {
        return array();
    }

    $arr = $GLOBALS['db']->GetAll('SELECT cat_id, cat_name, parent_id, is_show FROM ' . $GLOBALS['yp']->table('category') . 'WHERE is_show=1');

    if (empty($arr))
    {
        return array();
    }

    $index = 0;
    $cats  = array();
    $flag = false; // Eric @20210217

    while (1)
    {
        $flag = false; // Eric @20210217
        
        foreach ($arr AS $row)
        {
            if ($cat == $row['cat_id'])
            {
                $cat = $row['parent_id'];

                $flag = true; // Eric @20210217
                
                $cats[$index]['cat_id']   = $row['cat_id'];
                $cats[$index]['cat_name'] = $row['cat_name'];
                $cats[$index]['parent_id'] = $row['parent_id'];
                $cats[$index]['is_show'] = $row['is_show'];

                $index++;
                break;
            }
        }

        if ($index == 0 || $cat == 0)
        {
            break;
        }
        
        // Eric @20210217
        if (!$flag)
        {
            break;
        }
    }

    return $cats;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions