summaryrefslogtreecommitdiffstats
path: root/patches/mmc-utils-2018-03-27-gb4fe0c8c0e57/0001-lsmmc-replace-strncpy-with-memmove-on-overlapping-me.patch
blob: 858493d277c47fd8c7660ddaf0175bf940eef1fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
From: Khem Raj <raj.khem@gmail.com>
Date: Thu, 29 Mar 2018 01:19:14 -0700
Subject: [PATCH] lsmmc: replace strncpy with memmove on overlapping memory
 copy

here source and destination addresses are overlapping so using memmove is
going to be more efficient.

Additionally, the bounded size for copy is overflowing for first copy

In function 'strncpy',
    inlined from 'read_file' at lsmmc.c:356:3:
/mnt/a/oe/build/tmp/work/cortexa7t2hf-neon-vfpv4-bec-linux-gnueabi/mmc-utils/0.1-r0/recipe-sysroot/usr/include/bits/string_fortified.h:106:10: error: '__builtin_strncpy' accessing 4096 bytes at offsets 0 and 1 overlaps 4095 bytes at offset 1 [-Werror=restrict]
   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 lsmmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lsmmc.c b/lsmmc.c
index c4faa002e780..bcb854daf3e1 100644
--- a/lsmmc.c
+++ b/lsmmc.c
@@ -353,7 +353,7 @@ char *read_file(char *name)
 		line[strlen(line) - 1] = '\0';
 
 	while (isspace(line[0]))
-		strncpy(&line[0], &line[1], sizeof(line));
+		memmove(&line[0], &line[1], sizeof(line)-1);
 
 	return strdup(line);
 }