diff mbox series

mmc-utils: fix overlapping with strncpy

Message ID 20181020172325.7450-1-peron.clem@gmail.com (mailing list archive)
State New, archived
Headers show
Series mmc-utils: fix overlapping with strncpy | expand

Commit Message

Clément Péron Oct. 20, 2018, 5:23 p.m. UTC
GCC 8.2 warns about an overlapping using strncpy.

Replace strncpy with a memmove to avoid this issue.

In file included from /usr/include/string.h:494,
                 from lsmmc.c:46:
In function ‘strncpy’,
    inlined from ‘read_file’ at lsmmc.c:356:3:
/usr/include/x86_64-linux-gnu/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));
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make: *** [Makefile:36: lsmmc.o] Error 1

Signed-off-by: Clément Péron <peron.clem@gmail.com>
---
 lsmmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Ulf Hansson Oct. 24, 2018, 10:37 a.m. UTC | #1
+Chris

On 20 October 2018 at 19:23, Clément Péron <peron.clem@gmail.com> wrote:
> GCC 8.2 warns about an overlapping using strncpy.
>
> Replace strncpy with a memmove to avoid this issue.
>
> In file included from /usr/include/string.h:494,
>                  from lsmmc.c:46:
> In function ‘strncpy’,
>     inlined from ‘read_file’ at lsmmc.c:356:3:
> /usr/include/x86_64-linux-gnu/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));
>           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> cc1: all warnings being treated as errors
> make: *** [Makefile:36: lsmmc.o] Error 1
>
> Signed-off-by: Clément Péron <peron.clem@gmail.com>

You need post this to Chris Ball, as he maintains mmc-utils.

Kind regards
Uffe

> ---
>  lsmmc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lsmmc.c b/lsmmc.c
> index c4faa00..bcb854d 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);
>  }
> --
> 2.19.1
>
diff mbox series

Patch

diff --git a/lsmmc.c b/lsmmc.c
index c4faa00..bcb854d 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);
 }