Changed rtems_ofw_get_prop to use memcpy instead of strncpy
---
 bsps/shared/ofw/ofw.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/bsps/shared/ofw/ofw.c b/bsps/shared/ofw/ofw.c
index fa94bfbf05..9dec310247 100644
--- a/bsps/shared/ofw/ofw.c
+++ b/bsps/shared/ofw/ofw.c
@@ -198,7 +198,15 @@ ssize_t rtems_ofw_get_prop(
 
   if (prop == NULL && strcmp(propname, "name") == 0) {
     prop = fdt_get_name(fdtp, offset, &len);
-    strncpy(buf, prop, bufsize);
+
+    bufsize = MIN(len, bufsize - 1);
+    memcpy(buf, prop, bufsize);
+
+    /* Null terminate the buffer */
+    *((char *)buf + bufsize) = 0;
+
+    /* Return the length of the name including the null byte */
+    /* This is the behaviour in libBSD ofw_fdt_getprop */
     return len + 1;
   }
 
-- 
2.17.1

_______________________________________________
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Reply via email to