scripts/kconfig/symbol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
strcpy() performs no bounds checking and can lead to buffer overflows if
the input string exceeds the destination buffer size. This patch replaces
it with strlcpy(), which ensures the input is always NULL-terminated and
prevents overflows, following kernel coding guidelines.
Signed-off-by: Suchit Karunakaran <suchitkarunakaran@gmail.com>
---
scripts/kconfig/symbol.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 26ab10c0fd76..c44e8ac3e9fe 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -777,7 +777,7 @@ bool sym_set_string_value(struct symbol *sym, const char *newval)
else
return true;
- strcpy(val, newval);
+ strlcpy(val, newval, size);
free((void *)oldval);
sym_clear_all_valid();
--
2.50.1
Hi Suchit, kernel test robot noticed the following build errors: [auto build test ERROR on masahiroy-kbuild/kbuild] [also build test ERROR on linus/master v6.16-rc7 next-20250725] [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#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Suchit-Karunakaran/kconfig-replace-strcpy-with-strlcpy-in-symbol-c/20250727-031729 base: https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git kbuild patch link: https://lore.kernel.org/r/20250726191515.171012-1-suchitkarunakaran%40gmail.com patch subject: [PATCH] kconfig: replace strcpy() with strlcpy() in symbol.c config: arc-randconfig-002-20250727 (attached as .config) compiler: arc-linux-gcc (GCC) 8.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250727/202507270411.j9vfofzH-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202507270411.j9vfofzH-lkp@intel.com/ All error/warnings (new ones prefixed by >>): /usr/bin/ld: scripts/kconfig/symbol.o: in function `sym_set_string_value': >> symbol.c:(.text+0x14cb): undefined reference to `strlcpy' collect2: error: ld returned 1 exit status make[3]: *** [scripts/Makefile.host:123: scripts/kconfig/conf] Error 1 shuffle=618416945 make[3]: Target 'oldconfig' not remade because of errors. make[2]: *** [Makefile:735: oldconfig] Error 2 shuffle=618416945 make[1]: *** [Makefile:248: __sub-make] Error 2 shuffle=618416945 make[1]: Target 'oldconfig' not remade because of errors. make: *** [Makefile:248: __sub-make] Error 2 shuffle=618416945 make: Target 'oldconfig' not remade because of errors. -- scripts/kconfig/symbol.c: In function 'sym_set_string_value': >> scripts/kconfig/symbol.c:780:9: warning: implicit declaration of function 'strlcpy'; did you mean 'strncpy'? [-Wimplicit-function-declaration] 780 | strlcpy(val, newval, size); | ^~~~~~~ | strncpy /usr/bin/ld: scripts/kconfig/symbol.o: in function `sym_set_string_value': >> symbol.c:(.text+0x14cb): undefined reference to `strlcpy' collect2: error: ld returned 1 exit status make[3]: *** [scripts/Makefile.host:123: scripts/kconfig/conf] Error 1 shuffle=618416945 make[3]: Target 'olddefconfig' not remade because of errors. make[2]: *** [Makefile:735: olddefconfig] Error 2 shuffle=618416945 make[1]: *** [Makefile:248: __sub-make] Error 2 shuffle=618416945 make[1]: Target 'olddefconfig' not remade because of errors. make: *** [Makefile:248: __sub-make] Error 2 shuffle=618416945 make: Target 'olddefconfig' not remade because of errors. -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
© 2016 - 2025 Red Hat, Inc.