<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, May 3, 2021 at 11:23 PM Gedare Bloom <<a href="mailto:gedare@rtems.org">gedare@rtems.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Niteesh,<br>
<br>
This looks good to me. What/how did you test it?<br></blockquote><div><span class="gmail_default" style="font-size:small">I tested it using the ofw01 test</span> </div><div><div class="gmail_default" style="font-size:small"><a href="https://git.rtems.org/rtems/tree/testsuites/libtests/ofw01/init.c">https://git.rtems.org/rtems/tree/testsuites/libtests/ofw01/init.c</a></div><div class="gmail_default" style="font-size:small">and read EEPROM using i2c.</div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Gedare<br>
<br>
On Sat, May 1, 2021 at 6:31 AM G S Niteesh Babu <<a href="mailto:niteesh.gs@gmail.com" target="_blank">niteesh.gs@gmail.com</a>> wrote:<br>
><br>
> This patch adds asserts to fix coverity defects<br>
> 1) CID 1474437 (Out-of-bounds access)<br>
> 2) CID 1474436 (Out-of-bounds access)<br>
><br>
> From manual inspection, out of bounds access cannot occur due to<br>
> bounds checking but coverity fails to detect the checks.<br>
> We are adding asserts as a secondary check.<br>
> ---<br>
> bsps/shared/ofw/ofw.c | 12 +++++++++++-<br>
> 1 file changed, 11 insertions(+), 1 deletion(-)<br>
><br>
> diff --git a/bsps/shared/ofw/ofw.c b/bsps/shared/ofw/ofw.c<br>
> index f4b8b63931..0e0a7033ab 100644<br>
> --- a/bsps/shared/ofw/ofw.c<br>
> +++ b/bsps/shared/ofw/ofw.c<br>
> @@ -42,6 +42,7 @@<br>
> #include <assert.h><br>
> #include <rtems/sysinit.h><br>
> #include <ofw/ofw_test.h><br>
> +#include <rtems/score/assert.h><br>
><br>
> static void *fdtp = NULL;<br>
><br>
> @@ -186,6 +187,7 @@ ssize_t rtems_ofw_get_prop(<br>
> const void *prop;<br>
> int offset;<br>
> int len;<br>
> + int copy_len;<br>
> uint32_t cpuid;<br>
><br>
> offset = rtems_fdt_phandle_to_offset(node);<br>
> @@ -226,7 +228,9 @@ ssize_t rtems_ofw_get_prop(<br>
> return -1;<br>
> }<br>
><br>
> - bcopy(prop, buf, MIN(len, bufsize));<br>
> + copy_len = MIN(len, bufsize);<br>
> + _Assert(copy_len <= bufsize);<br>
> + memmove(prop, buf, copy_len);<br>
><br>
> return len;<br>
> }<br>
> @@ -637,6 +641,12 @@ int rtems_ofw_get_reg(<br>
> range.child_bus = fdt32_to_cpu(ptr[j].child_bus);<br>
> range.size = fdt32_to_cpu(ptr[j].size);<br>
><br>
> + /**<br>
> + * (buf + size - (sizeof(buf[0]) - 1) is the last valid<br>
> + * address for buf[i]. If buf[i] points to any address larger<br>
> + * than this, it will be an out of bound access<br>
> + */<br>
> + _Assert(&buf[i] < (buf + size - (sizeof(buf[0]) - 1)));<br>
> if (buf[i].start >= range.child_bus &&<br>
> buf[i].start < range.child_bus + range.size) {<br>
> offset = range.parent_bus - range.child_bus;<br>
> --<br>
> 2.17.1<br>
><br>
</blockquote></div></div>