[rtems commit] bsps/shared/ofw: Use strlcpy instead of strncpy

Christian Mauderer christianm at rtems.org
Mon Feb 8 20:25:38 UTC 2021


Module:    rtems
Branch:    master
Commit:    066687c43ad50af0e0cc66fe2f5e018bcc078d88
Changeset: http://git.rtems.org/rtems/commit/?id=066687c43ad50af0e0cc66fe2f5e018bcc078d88

Author:    G S Niteesh Babu <niteesh.gs at gmail.com>
Date:      Sat Feb  6 23:28:10 2021 +0530

bsps/shared/ofw: Use strlcpy instead of strncpy

Changed rtems_ofw_get_prop to use strlcpy instead of strncpy
to ensure the buffer is null terminated incase of overflow.

---

 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 fa94bfb..886ad02 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);
+
+    /* Node name's are 1-31 chars in length consisting of only
+     * ascii chars and are null terminated */
+    strlcpy(buf, prop, bufsize);
+
+    /* Return the length of the name including the null byte
+     * rather than the amount copied.
+     * This is the behaviour in libBSD ofw_fdt_getprop
+     */
     return len + 1;
   }
 



More information about the vc mailing list