Re: [PATCH] mmc: use memmove to avoid strncpy on overlapping strings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Hans-Christian,

Le dim. 4 nov. 2018 à 12:29, Hans-Christian Noren Egtvedt
<egtvedt@xxxxxxxxxxxx> a écrit :
>
> Using GCC 8.2.0 I see the following error.
>
> /usr/bin/gcc-8  -Wall -Werror -Wuninitialized -Wundef -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -g -O2 -Wp,-MMD,./.lsmmc.o.d,-MT,lsmmc.o -c lsmmc.c -o lsmmc.o
> 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
> Makefile:36: recipe for target 'lsmmc.o' failed
> make: *** [lsmmc.o] Error 1
>
> Hence replace the strncpy with memmove, since using strncpy on
> overlapping strings is not allowed.
>
> Signed-off-by: Hans-Christian Noren Egtvedt <egtvedt@xxxxxxxxxxxx>
> ---
>  lsmmc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lsmmc.c b/lsmmc.c
> index c4faa00..7637198 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);


Post the same patch a week ago : https://patchwork.kernel.org/patch/10654531/

Could you add your review ?

Thanks,
Clement
>
>
>         return strdup(line);
>  }
> --
> 2.17.1
>
>




[Index of Archives]     [Linux Memonry Technology]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux