Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1 | From 175ac0f362bf6121c3537e2f1760ad41c8f81367 Mon Sep 17 00:00:00 2001 |
| 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Thu, 29 Mar 2018 01:04:57 -0700 |
| 4 | Subject: [PATCH] lsmmc: replace strncpy with memmove on overlapping memory |
| 5 | copy |
| 6 | |
| 7 | here source and destination addresses are overlapping so using memmove is |
| 8 | going to be more efficient. |
| 9 | |
| 10 | Additionally, the bounded size for copy is overflowing for first copy |
| 11 | |
| 12 | In function 'strncpy', |
| 13 | inlined from 'read_file' at lsmmc.c:356:3: |
| 14 | /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] |
| 15 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); |
| 16 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 17 | |
| 18 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 19 | --- |
| 20 | Upstream-Status: Submitted [https://patchwork.kernel.org/patch/10314723/] |
| 21 | lsmmc.c | 2 +- |
| 22 | 1 file changed, 1 insertion(+), 1 deletion(-) |
| 23 | |
| 24 | diff --git a/lsmmc.c b/lsmmc.c |
| 25 | index c4faa00..bcb854d 100644 |
| 26 | --- a/lsmmc.c |
| 27 | +++ b/lsmmc.c |
| 28 | @@ -353,7 +353,7 @@ char *read_file(char *name) |
| 29 | line[strlen(line) - 1] = '\0'; |
| 30 | |
| 31 | while (isspace(line[0])) |
| 32 | - strncpy(&line[0], &line[1], sizeof(line)); |
| 33 | + memmove(&line[0], &line[1], sizeof(line)-1); |
| 34 | |
| 35 | return strdup(line); |
| 36 | } |