Re: [PATCH 1/1] init: Add "hostname" kernel parameter

From: kernel test robot
Date: Thu May 05 2022 - 20:52:17 EST


Hi Dan,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linux/master]
[also build test WARNING on hnaz-mm/master linus/master v5.18-rc5 next-20220505]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url: https://github.com/intel-lab-lkp/linux/commits/Dan-Moulding/Allow-setting-hostname-before-userspace-starts/20220506-023146
base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 107c948d1d3e61d10aee9d0f7c3d81bbee9842af
config: riscv-randconfig-r042-20220505 (https://download.01.org/0day-ci/archive/20220506/202205060821.6KCNxZBf-lkp@xxxxxxxxx/config)
compiler: riscv64-linux-gcc (GCC) 11.3.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://github.com/intel-lab-lkp/linux/commit/1071875b349d9b8307eb0f4d23dda06a2301fe03
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Dan-Moulding/Allow-setting-hostname-before-userspace-starts/20220506-023146
git checkout 1071875b349d9b8307eb0f4d23dda06a2301fe03
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash

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

All warnings (new ones prefixed by >>):

init/version.c: In function 'early_hostname':
>> init/version.c:45:9: warning: 'strncpy' specified bound 65 equals destination size [-Wstringop-truncation]
45 | strncpy(init_uts_ns.name.nodename, arg, bufsize);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


vim +/strncpy +45 init/version.c

39
40 static int __init early_hostname(char *arg)
41 {
42 size_t bufsize = sizeof(init_uts_ns.name.nodename);
43 size_t maxlen = bufsize - 1;
44
> 45 strncpy(init_uts_ns.name.nodename, arg, bufsize);
46 if (strlen(arg) > maxlen) {
47 pr_warn("hostname parameter exceeds %zd characters and will be truncated",
48 maxlen);
49 init_uts_ns.name.nodename[maxlen] = '\0';
50 }
51 return 0;
52 }
53 early_param("hostname", early_hostname);
54

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