sandbox: Use memmove() to move overlapping regions
authorSimon Glass <sjg@chromium.org>
Tue, 13 Nov 2018 22:55:20 +0000 (15:55 -0700)
committerSimon Glass <sjg@chromium.org>
Thu, 29 Nov 2018 16:30:05 +0000 (09:30 -0700)
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 memmove() instead.

Reported-by: Coverity (CID: 173279)
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Alexander Graf <agraf@suse.de>
arch/sandbox/cpu/os.c

index aa926943427230c92a11ea2a284f8e8732ba5a9b..62e05c554a15e53c4c18e8596ad6066f5c3a7b0d 100644 (file)
@@ -735,9 +735,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 + 4, strlen(p + 4) + 1);
                fd = os_open(fname, O_RDONLY);
                if (fd >= 0) {
                        close(fd);