[rtems commit] cpukit/libmisc/monitor: Fix an illegal string copy

Sebastian Huber sebh at rtems.org
Mon Oct 12 06:50:02 UTC 2020


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

Author:    Frank Kühndel <frank.kuehndel at embedded-brains.de>
Date:      Mon Oct  5 16:49:14 2020 +0200

cpukit/libmisc/monitor: Fix an illegal string copy

This is actually an illegal use of strcpy() because one is not allowed to
use this function with overlapping source and destination buffers; whereas
memmove() is explicitly designed to handle such cases.

The compiler warning was:

../../../cpukit/libmisc/monitor/mon-editor.c:342:15: warning:
'strcpy' accessing 1 byte at offsets [0, 75] and [0, 75] overlaps
1 byte at offset [0, 74] [-Wrestrict]

---

 cpukit/libmisc/monitor/mon-editor.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/cpukit/libmisc/monitor/mon-editor.c b/cpukit/libmisc/monitor/mon-editor.c
index a3b408a..dcea9fc 100644
--- a/cpukit/libmisc/monitor/mon-editor.c
+++ b/cpukit/libmisc/monitor/mon-editor.c
@@ -339,7 +339,8 @@ rtems_monitor_line_editor (
             {
               int end;
               int bs;
-              strcpy (&buffer[pos], &buffer[pos + 1]);
+              memmove (&buffer[pos], &buffer[pos + 1],
+                       strlen (&buffer[pos + 1]) + 1);
               fprintf(stdout,"\r%s $ %s", monitor_prompt, buffer);
               end = (int) strlen (buffer);
               for (bs = 0; bs < (end - pos); bs++)



More information about the vc mailing list