dgibson / dtc

Device Tree Compiler
218 stars 130 forks source link

Unchecked return value in fdt_add_subnode_namelen() #46

Closed longr96 closed 3 years ago

longr96 commented 3 years ago

RTEMS (RTEMS.org) is a free single process, multi-threaded real-time operating system with a long history. Your dtc toolchain has been incorporated into RTEMS. The RTEMS Project is a member of the Coverity Scan program and it flagged an issue with /dtc/libfdt/fdt_rw.c. In trying to be good citizens of the wider open source community, the project wants these issues to be reported to the upstream owner along with a fix or suggestions. This is one of those reports.

When Coverity Scan was ran on some of your code, a "Unchecked return value" error was found at line 352 in fdt_rw.c. For similar errors that we received for RTEMS, we created a macro that will assert the value returned and "use" the return value like so.

int status = fdt_next_tag(fdt, parentoffset, &nextoffset);
assert(status == 0);
(void)status;

You can just use the "(void)fdt_next_tag()" if you don't care to check the return value of the functional call at all, but this is just a suggestion.

dgibson commented 3 years ago

We can't use assert() in libfdt, because we it needs to be usable in very constrained environments (like bootloaders) which might not have an assert() (or if they do it might not work like the libc one). Our rough equivalent to assert()s is to return FDT_ERR_INTERNAL.

I'm not sure why our own Coverity didn't pick this one up, but in any case I've made what should be a fix in a somewhat different way.