<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 Fri, Feb 5, 2021 at 11:52 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"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 5, 2021 at 10:41 AM G S Niteesh Babu <<a href="mailto:niteesh.gs@gmail.com" target="_blank">niteesh.gs@gmail.com</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">Changed rtems_ofw_get_prop to use memcpy instead of strncpy<br>
---<br>
 bsps/shared/ofw/ofw.c | 10 +++++++++-<br>
 1 file changed, 9 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/bsps/shared/ofw/ofw.c b/bsps/shared/ofw/ofw.c<br>
index fa94bfbf05..9dec310247 100644<br>
--- a/bsps/shared/ofw/ofw.c<br>
+++ b/bsps/shared/ofw/ofw.c<br>
@@ -198,7 +198,15 @@ ssize_t rtems_ofw_get_prop(<br>
<br>
   if (prop == NULL && strcmp(propname, "name") == 0) {<br>
     prop = fdt_get_name(fdtp, offset, &len);<br>
-    strncpy(buf, prop, bufsize);<br>
+<br>
+    bufsize = MIN(len, bufsize - 1);<br></blockquote><div>ok, reserving 1 byte for the \0. It could be worth adding a comment here to that effect<span class="gmail_default"></span> </div></div></div></blockquote><div><span class="gmail_default" style="font-size:small">Will do.</span> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+    memcpy(buf, prop, bufsize);<br>
+<br>
+    /* Null terminate the buffer */<br>
+    *((char *)buf + bufsize) = 0;<br></blockquote><div>that gets written here. looks fine to me.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+    /* Return the length of the name including the null byte */<br>
+    /* This is the behaviour in libBSD ofw_fdt_getprop */<br>
     return len + 1;<br></blockquote><div>shouldn't it be bufsize+1? if it got truncated by the MIN?</div></div></div></blockquote><div> </div><div><span class="gmail_default" style="font-size:small">We have to return the size of the value instead of the amount copied.</span></div><div><span class="gmail_default" style="font-size:small"><a href="https://www.gsp.com/cgi-bin/man.cgi?section=9&topic=OF_GETPROP">https://www.gsp.com/cgi-bin/man.cgi?section=9&topic=OF_GETPROP</a></span></div><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"><div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
   }<br>
<br>
-- <br>
2.17.1<br>
<br>
</blockquote></div></div>
</blockquote></div></div>