diff mbox series

[U-Boot,v2,3/8] sandbox: Use memcpy() to move overlapping regions

Message ID 20180612060502.196817-4-sjg@chromium.org
State Accepted
Delegated to: Tom Rini
Headers show
Series Fix some coverity warnings | expand

Commit Message

Simon Glass June 12, 2018, 6:04 a.m. UTC
The use of strcpy() to remove characters at the start of a string is safe
in U-Boot, since we know the implementation. But in os.c we are using the
C library's strcpy() function, where this behaviour is not permitted.

Update the code to use memcpy() instead.

Reported-by: Coverity (CID: 173279)
Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2:
- Also remove the leading / from the "/spl" path

 arch/sandbox/cpu/os.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Tom Rini June 19, 2018, 6:40 p.m. UTC | #1
On Tue, Jun 12, 2018 at 12:04:57AM -0600, Simon Glass wrote:

> The use of strcpy() to remove characters at the start of a string is safe
> in U-Boot, since we know the implementation. But in os.c we are using the
> C library's strcpy() function, where this behaviour is not permitted.
> 
> Update the code to use memcpy() instead.
> 
> Reported-by: Coverity (CID: 173279)
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
> 
> Changes in v2:
> - Also remove the leading / from the "/spl" path
> 
>  arch/sandbox/cpu/os.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

This ends up breaking the sandbox_spl portions of 'make tests.
diff mbox series

Patch

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 5839932b00..5a12b8c677 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -585,9 +585,10 @@  int os_find_u_boot(char *fname, int maxlen)
 	}
 
 	/* Look for 'u-boot' in the parent directory of spl/ */
-	p = strstr(fname, "/spl/");
+	p = strstr(fname, "spl/");
 	if (p) {
-		strcpy(p, p + 4);
+		/* Remove the "spl" characters */
+		memmove(p, p + 3, strlen(p + 3) + 1);
 		fd = os_open(fname, O_RDONLY);
 		if (fd >= 0) {
 			close(fd);