[linux-next:master 4364/5667] include/linux/string.h:303:42: warning: 'strnlen' specified bound 4 exceeds source size 3

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

 



tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   840126e36e8ff272cb63158646433fa1324533d9
commit: 14fa26474621071a2f62696261562fdb40c07f5c [4364/5667] string: Introduce strtomem() and strtomem_pad()
config: openrisc-randconfig-r024-20220906 (https://download.01.org/0day-ci/archive/20220907/202209070728.o3stvgVt-lkp@xxxxxxxxx/config)
compiler: or1k-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=14fa26474621071a2f62696261562fdb40c07f5c
        git remote add linux-next https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
        git fetch --no-tags linux-next master
        git checkout 14fa26474621071a2f62696261562fdb40c07f5c
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=openrisc SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@xxxxxxxxx>

All warnings (new ones prefixed by >>):

   In file included from include/linux/kernel.h:26,
                    from include/linux/cpumask.h:10,
                    from include/linux/smp.h:13,
                    from include/linux/lockdep.h:14,
                    from include/linux/spinlock.h:62,
                    from include/linux/kref.h:16,
                    from include/kunit/test.h:20,
                    from lib/memcpy_kunit.c:7:
   lib/memcpy_kunit.c: In function 'strtomem_test':
>> include/linux/string.h:303:42: warning: 'strnlen' specified bound 4 exceeds source size 3 [-Wstringop-overread]
     303 |         memcpy(dest, src, min(_dest_len, strnlen(src, _dest_len)));     \
   include/linux/minmax.h:32:39: note: in definition of macro '__cmp_once'
      32 |                 typeof(y) unique_y = (y);               \
         |                                       ^
   include/linux/minmax.h:45:25: note: in expansion of macro '__careful_cmp'
      45 | #define min(x, y)       __careful_cmp(x, y, <)
         |                         ^~~~~~~~~~~~~
   include/linux/string.h:303:27: note: in expansion of macro 'min'
     303 |         memcpy(dest, src, min(_dest_len, strnlen(src, _dest_len)));     \
         |                           ^~~
   lib/memcpy_kunit.c:290:9: note: in expansion of macro 'strtomem'
     290 |         strtomem(wrap.output, input);
         |         ^~~~~~~~
   lib/memcpy_kunit.c:275:27: note: source object allocated here
     275 |         static const char input[] = "hi";
         |                           ^~~~~
   In file included from include/linux/bitmap.h:11,
                    from include/linux/cpumask.h:12:
   include/linux/string.h:282:9: warning: 'strnlen' specified bound 4 exceeds source size 3 [-Wstringop-overread]
     282 |         memcpy_and_pad(dest, _dest_len, src, strnlen(src, _dest_len), pad); \
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   lib/memcpy_kunit.c:308:9: note: in expansion of macro 'strtomem_pad'
     308 |         strtomem_pad(wrap.output, input, 0xAA);
         |         ^~~~~~~~~~~~
   lib/memcpy_kunit.c:275:27: note: source object allocated here
     275 |         static const char input[] = "hi";
         |                           ^~~~~


vim +/strnlen +303 include/linux/string.h

   284	
   285	/**
   286	 * strtomem - Copy NUL-terminated string to non-NUL-terminated buffer
   287	 *
   288	 * @dest: Pointer of destination character array (marked as __nonstring)
   289	 * @src: Pointer to NUL-terminated string
   290	 *
   291	 * This is a replacement for strncpy() uses where the destination is not
   292	 * a NUL-terminated string, but with bounds checking on the source size, and
   293	 * without trailing padding. If padding is required, use strtomem_pad().
   294	 *
   295	 * Note that the size of @dest is not an argument, as the length of @dest
   296	 * must be discoverable by the compiler.
   297	 */
   298	#define strtomem(dest, src)	do {					\
   299		const size_t _dest_len = __builtin_object_size(dest, 1);	\
   300										\
   301		BUILD_BUG_ON(!__builtin_constant_p(_dest_len) ||		\
   302			     _dest_len == (size_t)-1);				\
 > 303		memcpy(dest, src, min(_dest_len, strnlen(src, _dest_len)));	\
   304	} while (0)
   305	

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux