unittest: gcc-11 errors for clib_strcpy, clib_strstr, clib_strcat, and clib_strncat 30/34330/5
authorSteven Luong <sluong@cisco.com>
Wed, 3 Nov 2021 22:33:21 +0000 (15:33 -0700)
committerDamjan Marion <dmarion@me.com>
Fri, 5 Nov 2021 19:20:10 +0000 (19:20 +0000)
commit51ddd38deb5866b10bbe9712ba6e8c4fb6da6381
tree5a326543ec4cc0e4f8b72c19c0853303ada7bef4
parent6259406668cee37d39ef3eb0b17ee5dc94ff02fe
unittest: gcc-11 errors for clib_strcpy, clib_strstr, clib_strcat, and clib_strncat

There are 3 versions of the string functions. For example, for strcpy,
they are
1. strcpy(dst, src) -- the legacy unsafe version
2. strcpy_s(dst, dmax, src) -- C11 safeC version which has an addition argument
named dmax.
3. clib_strcpy(dst,src) -- clib version to enable legacy code that uses strcpy
to make use of strcpy_s without adding the additional argument, dmax, which is
required by the C11 safeC version.

The implementation for the clib version is to artificially provide dmax to
strcpy_s. In this case, it uses 4096 which assumes that if the legacy code
works without blowing up, it is likely to work with the clib version without
problem.

gcc-11 is getting smarter by checking if dmax is within the object's boundary.
When the object is declared as static array, it will flag a warning/error
if dmax is out of bound for the object since the real size of dst can be
determined at compile time.

There is no way to find the real size of dst if the object is dynamically
allocated at compile time. For this reason, we simply can't provide support
for the clib version of the function anymore. If any code is using the clib
version, the choice is to migrate to the safeC version.

Type: fix
Fixes: b0598497afde60146fe8480331c9f96e7a79475a

Signed-off-by: Steven Luong <sluong@cisco.com>
Change-Id: I99fa59c878331f995b734588cca3906a1d4782f5
src/plugins/unittest/string_test.c
src/vppinfra/string.h
test/test_string.py