dgibson / dtc

Device Tree Compiler
218 stars 130 forks source link

valid_header function may be have some problem. #52

Closed juiceRv closed 1 year ago

juiceRv commented 3 years ago

https://github.com/dgibson/dtc/blob/ecfb438c07fa468a129e81c7d84c7c293c7b0150/fdtdump.c#L166 This function should be modified like this?

static bool valid_header(char *p, size_t len)
{
    if (len < sizeof(struct fdt_header) ||
        fdt_magic(p) != FDT_MAGIC ||
        fdt_version(p) > MAX_VERSION ||
        fdt_last_comp_version(p) > MAX_VERSION ||
        fdt_totalsize(p) > len ||
        fdt_off_dt_struct(p) >= len ||
        fdt_off_dt_strings(p) >= len)
        return 0;
    else
        return 1;
}
juiceRv commented 3 years ago

i look some code like this https://github.com/torvalds/linux/blob/5bfc75d92efd494db37f5c4c173d3639d4772966/scripts/dtc/flattree.c#L876

dgibson commented 1 year ago

@juiceRv sorry, I don't understand what change you're suggesting. The code you quote appears to be identical to what's in dtc now.

dgibson commented 1 year ago

No response to query, so closing.