diff mbox series

mmc: use memmove to avoid strncpy on overlapping strings

Message ID 20181104104356.18120-1-egtvedt@samfundet.no (mailing list archive)
State New, archived
Headers show
Series mmc: use memmove to avoid strncpy on overlapping strings | expand

Commit Message

Hans-Christian Noren Egtvedt Nov. 4, 2018, 10:43 a.m. UTC
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@samfundet.no>
---
 lsmmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Clément Péron Nov. 5, 2018, 7:15 a.m. UTC | #1
Hi Hans-Christian,

Le dim. 4 nov. 2018 à 12:29, Hans-Christian Noren Egtvedt
<egtvedt@samfundet.no> 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@samfundet.no>
> ---
>  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
>
>
Hans-Christian Noren Egtvedt Nov. 5, 2018, 3:29 p.m. UTC | #2
Around Mon 05 Nov 2018 08:15:50 +0100 or thereabout, Clément Péron wrote:

Hello Clément,

> Le dim. 4 nov. 2018 à 12:29, Hans-Christian Noren Egtvedt
> <egtvedt@samfundet.no> 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@samfundet.no>
>> ---
>>  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 ?

That looks good by me, however I could not immediate figure out how to ack a
patch in patchwork. I even tried creating an account.

<snipp>
Clément Péron Nov. 5, 2018, 4:12 p.m. UTC | #3
Hi Hans-Christian

On Mon, 5 Nov 2018 at 16:29, Hans-Christian Noren Egtvedt
<egtvedt@samfundet.no> wrote:
>
> Around Mon 05 Nov 2018 08:15:50 +0100 or thereabout, Clément Péron wrote:
>
> Hello Clément,
>
> > Le dim. 4 nov. 2018 à 12:29, Hans-Christian Noren Egtvedt
> > <egtvedt@samfundet.no> 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@samfundet.no>
> >> ---
> >>  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 ?
>
> That looks good by me, however I could not immediate figure out how to ack a
> patch in patchwork. I even tried creating an account.

I thought you were a subscriber of the linux-mmc ML.

Patchwork is more a patch viewer/manager, you should subscribe to the
linux-mmc ML to be able to reply and add your tags.

I will add you in the next refresh,

Regards,
Clement


>
> <snipp>
>
> --
> mvh
> Hans-Christian Noren Egtvedt
Hans-Christian Noren Egtvedt Nov. 5, 2018, 7:03 p.m. UTC | #4
Around Mon 05 Nov 2018 17:12:21 +0100 or thereabout, Clément Péron wrote:

Hello Clément,

> On Mon, 5 Nov 2018 at 16:29, Hans-Christian Noren Egtvedt <egtvedt@samfundet.no> wrote:
>> Around Mon 05 Nov 2018 08:15:50 +0100 or thereabout, Clément Péron wrote:
>> > Le dim. 4 nov. 2018 à 12:29, Hans-Christian Noren Egtvedt
>> > <egtvedt@samfundet.no> a écrit :

<snipp patch>

>> > Post the same patch a week ago : https://patchwork.kernel.org/patch/10654531/
>> >
>> > Could you add your review ?
>>
>> That looks good by me, however I could not immediate figure out how to ack a
>> patch in patchwork. I even tried creating an account.
> 
> I thought you were a subscriber of the linux-mmc ML.

No, sorry, I did not plan to subscribe to the linux-mmc mailing list. The
mmc-util works well for me, with exception to this minor change required for
GCC 8 compilation.

> Patchwork is more a patch viewer/manager, you should subscribe to the
> linux-mmc ML to be able to reply and add your tags.

If you bounce the original patch email to me, I can reply to it.

> I will add you in the next refresh,
>

Thanks.
diff mbox series

Patch

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);
 
 	return strdup(line);
 }