[TESTSUITE]Use strncpy instead of strcpy in testsuite/gcc.dg/memcmp-1.c

Renlin Li renlin.li@foss.arm.com
Wed Aug 30 09:34:00 GMT 2017


Hi,

In test_driver_memcmp function, I found buf1 and buf2 is not properly
terminated with null character.

In lib_strncmp, strcpy will be called with buf1 and buf2.
The normal implementation of strcpy function has a loop to copy character from source
to destination one by one until a null character is encountered.

If the string is not properly terminated, this will cause the strcpy read/write
memory beyond the boundary.

Here I changed the strcpy into strncpy to constraint the function to visit
legal memory only.

Test Okay without any problem. Okay to commit?

Regard,
Renlin


gcc/testsuite/ChangeLog:

2017-08-30  Renlin Li  <renlin.li@arm.com>

	* gcc.dg/memcmp-1.c (test_strncmp): Use strncpy instead of strcpy.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tmp.diff
Type: text/x-patch
Size: 634 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20170830/ce09318f/attachment.bin>


More information about the Gcc-patches mailing list