[PATCH] Kconfig:Uses glibc so strscpy has to be manually- added

Biancaa Ramesh posted 1 patch 3 months, 2 weeks ago
scripts/kconfig/confdata.c | 16 +++++++++++++++-
scripts/kconfig/symbol.c   | 16 +++++++++++++++-
scripts/kconfig/util.c     | 17 ++++++++++++++++-
3 files changed, 46 insertions(+), 3 deletions(-)
[PATCH] Kconfig:Uses glibc so strscpy has to be manually- added
Posted by Biancaa Ramesh 3 months, 2 weeks ago
Signed-off-by: Biancaa Ramesh <biancaa2210329@ssn.edu.in>
---
 scripts/kconfig/confdata.c | 16 +++++++++++++++-
 scripts/kconfig/symbol.c   | 16 +++++++++++++++-
 scripts/kconfig/util.c     | 17 ++++++++++++++++-
 3 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 9599a0408862..c0fef4cd6b60 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -22,6 +22,20 @@
 #include "internal.h"
 #include "lkc.h"
 
+#define HAVE_STRSCPY 0
+#ifndef HAVE_STRSCPY
+static size_t strscpy(char *dest, const char *src, size_t count)
+{
+    size_t i;
+    if (count == 0)
+        return 0;
+    for (i = 0; i < count - 1 && src[i]; i++)
+        dest[i] = src[i];
+    dest[i] = '\0';
+    return i;
+}
+#endif
+
 struct gstr autoconf_cmd;
 
 /* return true if 'path' exists, false otherwise */
@@ -140,7 +154,7 @@ static int conf_touch_dep(const char *name)
 	if (depfile_prefix_len + strlen(name) + 1 > sizeof(depfile_path))
 		return -1;
 
-	strcpy(depfile_path + depfile_prefix_len, name);
+	strscpy(depfile_path + depfile_prefix_len, name);
 
 	fd = open(depfile_path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
 	if (fd == -1)
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 7e81b3676ee9..0c6746854617 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -14,6 +14,20 @@
 #include "internal.h"
 #include "lkc.h"
 
+#define HAVE_STRSCPY 0
+#ifndef HAVE_STRSCPY
+static size_t strscpy(char *dest, const char *src, size_t count)
+{
+    size_t i;
+    if (count == 0)
+        return 0;
+    for (i = 0; i < count - 1 && src[i]; i++)
+        dest[i] = src[i];
+    dest[i] = '\0';
+    return i;
+}
+#endif
+
 struct symbol symbol_yes = {
 	.name = "y",
 	.type = S_TRISTATE,
@@ -795,7 +809,7 @@ bool sym_set_string_value(struct symbol *sym, const char *newval)
 	else
 		return true;
 
-	strcpy(val, newval);
+	strscpy(val, newval);
 	free((void *)oldval);
 	sym_clear_all_valid();
 
diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c
index 5cdcee144b58..176ec03bb3f0 100644
--- a/scripts/kconfig/util.c
+++ b/scripts/kconfig/util.c
@@ -13,6 +13,21 @@
 #include <xalloc.h>
 #include "lkc.h"
 
+#define HAVE_STRSCPY 0
+#ifndef HAVE_STRSCPY
+static size_t strscpy(char *dest, const char *src, size_t count)
+{
+    size_t i;
+    if (count == 0)
+        return 0;
+    for (i = 0; i < count - 1 && src[i]; i++)
+        dest[i] = src[i];
+    dest[i] = '\0';
+    return i;
+}
+#endif
+
+
 /* hash table of all parsed Kconfig files */
 static HASHTABLE_DEFINE(file_hashtable, 1U << 11);
 
@@ -52,7 +67,7 @@ struct gstr str_new(void)
 	gs.s = xmalloc(sizeof(char) * 64);
 	gs.len = 64;
 	gs.max_width = 0;
-	strcpy(gs.s, "\0");
+	strscpy(gs.s, "\0");
 	return gs;
 }
 
-- 
2.43.0


-- 
::DISCLAIMER::

---------------------------------------------------------------------
The 
contents of this e-mail and any attachment(s) are confidential and
intended 
for the named recipient(s) only. Views or opinions, if any,
presented in 
this email are solely those of the author and may not
necessarily reflect 
the views or opinions of SSN Institutions (SSN) or its
affiliates. Any form 
of reproduction, dissemination, copying, disclosure,
modification, 
distribution and / or publication of this message without the
prior written 
consent of authorized representative of SSN is strictly
prohibited. If you 
have received this email in error please delete it and
notify the sender 
immediately.
---------------------------------------------------------------------
Header of this mail should have a valid DKIM signature for the domain 
ssn.edu.in <http://www.ssn.edu.in/>
Re: [PATCH] Kconfig:Uses glibc so strscpy has to be manually- added
Posted by kernel test robot 3 months, 2 weeks ago
Hi Biancaa,

kernel test robot noticed the following build errors:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.18-rc2 next-20251022]
[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/Biancaa-Ramesh/Kconfig-Uses-glibc-so-strscpy-has-to-be-manually-added/20251022-011608
base:   linus/master
patch link:    https://lore.kernel.org/r/20251021171446.46942-1-biancaa2210329%40ssn.edu.in
patch subject: [PATCH] Kconfig:Uses glibc so strscpy has to be manually- added
config: x86_64-randconfig-002-20251022 (attached as .config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251022/202510221515.tlpfL3lX-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/202510221515.tlpfL3lX-lkp@intel.com/

All errors (new ones prefixed by >>):

>> scripts/kconfig/confdata.c:157:2: error: call to undeclared function 'strscpy'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     157 |         strscpy(depfile_path + depfile_prefix_len, name);
         |         ^
>> scripts/kconfig/util.c:70:2: error: call to undeclared function 'strscpy'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
      70 |         strscpy(gs.s, "\0");
         |         ^
   scripts/kconfig/symbol.c1 error generated.
   :812:2: error: call to undeclared function 'strscpy'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     812 |         strscpy(val, newval);
         |         ^
   make[3]: *** [scripts/Makefile.host:131: scripts/kconfig/util.o] Error 1 shuffle=3058352405
   1 error generated.
   make[3]: *** [scripts/Makefile.host:131: scripts/kconfig/confdata.o] Error 1 shuffle=3058352405
   1 error generated.
   make[3]: *** [scripts/Makefile.host:131: scripts/kconfig/symbol.o] Error 1 shuffle=3058352405
   make[3]: Target 'oldconfig' not remade because of errors.
   make[2]: *** [Makefile:742: oldconfig] Error 2 shuffle=3058352405
   make[1]: *** [Makefile:248: __sub-make] Error 2 shuffle=3058352405
   make[1]: Target 'oldconfig' not remade because of errors.
   make: *** [Makefile:248: __sub-make] Error 2 shuffle=3058352405
   make: Target 'oldconfig' not remade because of errors.
--
>> scripts/kconfig/symbol.c:812:2: error: call to undeclared function 'strscpy'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     812 |         strscpy(val, newval);
         |         ^
>> scripts/kconfig/confdata.c:157:2: error: call to undeclared function 'strscpy'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     157 |         strscpy(depfile_path + depfile_prefix_len, name);
         |         ^
>> scripts/kconfig/util.c:70:2: error: call to undeclared function 'strscpy'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
      70 |         strscpy(gs.s, "\0");
         |         ^
   1 error generated.
   1 error generated.
   make[3]: *** [scripts/Makefile.host:131: scripts/kconfig/confdata.o] Error 1 shuffle=3058352405
   make[3]: *** [scripts/Makefile.host:131: scripts/kconfig/util.o] Error 1 shuffle=3058352405
   1 error generated.
   make[3]: *** [scripts/Makefile.host:131: scripts/kconfig/symbol.o] Error 1 shuffle=3058352405
   make[3]: Target 'olddefconfig' not remade because of errors.
   make[2]: *** [Makefile:742: olddefconfig] Error 2 shuffle=3058352405
   make[1]: *** [Makefile:248: __sub-make] Error 2 shuffle=3058352405
   make[1]: Target 'olddefconfig' not remade because of errors.
   make: *** [Makefile:248: __sub-make] Error 2 shuffle=3058352405
   make: Target 'olddefconfig' not remade because of errors.


vim +/strscpy +157 scripts/kconfig/confdata.c

   147	
   148	/* touch depfile for symbol 'name' */
   149	static int conf_touch_dep(const char *name)
   150	{
   151		int fd;
   152	
   153		/* check overflow: prefix + name + '\0' must fit in buffer. */
   154		if (depfile_prefix_len + strlen(name) + 1 > sizeof(depfile_path))
   155			return -1;
   156	
 > 157		strscpy(depfile_path + depfile_prefix_len, name);
   158	
   159		fd = open(depfile_path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
   160		if (fd == -1)
   161			return -1;
   162		close(fd);
   163	
   164		return 0;
   165	}
   166	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH] Kconfig:Uses glibc so strscpy has to be manually- added
Posted by kernel test robot 3 months, 2 weeks ago
Hi Biancaa,

kernel test robot noticed the following build errors:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.18-rc2 next-20251022]
[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/Biancaa-Ramesh/Kconfig-Uses-glibc-so-strscpy-has-to-be-manually-added/20251022-011608
base:   linus/master
patch link:    https://lore.kernel.org/r/20251021171446.46942-1-biancaa2210329%40ssn.edu.in
patch subject: [PATCH] Kconfig:Uses glibc so strscpy has to be manually- added
config: arm-randconfig-r071-20251022 (attached as .config)
compiler: arm-linux-gnueabi-gcc (GCC) 14.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251022/202510221519.nzy5mUJ3-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/202510221519.nzy5mUJ3-lkp@intel.com/

All errors (new ones prefixed by >>):

   scripts/kconfig/util.c: In function 'str_new':
>> scripts/kconfig/util.c:70:9: error: implicit declaration of function 'strscpy'; did you mean 'strlcpy'? [-Wimplicit-function-declaration]
      70 |         strscpy(gs.s, "\0");
         |         ^~~~~~~
         |         strlcpy
   scripts/kconfig/symbol.c: In function 'sym_set_string_value':
>> scripts/kconfig/symbol.c:812:9: error: implicit declaration of function 'strscpy'; did you mean 'strlcpy'? [-Wimplicit-function-declaration]
     812 |         strscpy(val, newval);
         |         ^~~~~~~
         |         strlcpy
   make[3]: *** [scripts/Makefile.host:131: scripts/kconfig/util.o] Error 1
   scripts/kconfig/confdata.c: In function 'conf_touch_dep':
>> scripts/kconfig/confdata.c:157:9: error: implicit declaration of function 'strscpy'; did you mean 'strlcpy'? [-Wimplicit-function-declaration]
     157 |         strscpy(depfile_path + depfile_prefix_len, name);
         |         ^~~~~~~
         |         strlcpy
   make[3]: *** [scripts/Makefile.host:131: scripts/kconfig/confdata.o] Error 1
   make[3]: *** [scripts/Makefile.host:131: scripts/kconfig/symbol.o] Error 1
   make[3]: Target 'oldconfig' not remade because of errors.
   make[2]: *** [Makefile:742: oldconfig] Error 2
   make[1]: *** [Makefile:248: __sub-make] Error 2
   make[1]: Target 'oldconfig' not remade because of errors.
   make: *** [Makefile:248: __sub-make] Error 2
   make: Target 'oldconfig' not remade because of errors.
--
   scripts/kconfig/util.c: In function 'str_new':
>> scripts/kconfig/util.c:70:9: error: implicit declaration of function 'strscpy'; did you mean 'strlcpy'? [-Wimplicit-function-declaration]
      70 |         strscpy(gs.s, "\0");
         |         ^~~~~~~
         |         strlcpy
   make[3]: *** [scripts/Makefile.host:131: scripts/kconfig/util.o] Error 1
   scripts/kconfig/confdata.c: In function 'conf_touch_dep':
>> scripts/kconfig/confdata.c:157:9: error: implicit declaration of function 'strscpy'; did you mean 'strlcpy'? [-Wimplicit-function-declaration]
     157 |         strscpy(depfile_path + depfile_prefix_len, name);
         |         ^~~~~~~
         |         strlcpy
   scripts/kconfig/symbol.c: In function 'sym_set_string_value':
>> scripts/kconfig/symbol.c:812:9: error: implicit declaration of function 'strscpy'; did you mean 'strlcpy'? [-Wimplicit-function-declaration]
     812 |         strscpy(val, newval);
         |         ^~~~~~~
         |         strlcpy
   make[3]: *** [scripts/Makefile.host:131: scripts/kconfig/confdata.o] Error 1
   make[3]: *** [scripts/Makefile.host:131: scripts/kconfig/symbol.o] Error 1
   make[3]: Target 'olddefconfig' not remade because of errors.
   make[2]: *** [Makefile:742: olddefconfig] Error 2
   make[1]: *** [Makefile:248: __sub-make] Error 2
   make[1]: Target 'olddefconfig' not remade because of errors.
   make: *** [Makefile:248: __sub-make] Error 2
   make: Target 'olddefconfig' not remade because of errors.


vim +70 scripts/kconfig/util.c

    62	
    63	/* Allocate initial growable string */
    64	struct gstr str_new(void)
    65	{
    66		struct gstr gs;
    67		gs.s = xmalloc(sizeof(char) * 64);
    68		gs.len = 64;
    69		gs.max_width = 0;
  > 70		strscpy(gs.s, "\0");
    71		return gs;
    72	}
    73	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH] Kconfig:Uses glibc so strscpy has to be manually- added
Posted by Markus Elfring 3 months, 2 weeks ago
…
> ---
>  scripts/kconfig/confdata.c | 16 +++++++++++++++-
>  scripts/kconfig/symbol.c   | 16 +++++++++++++++-
>  scripts/kconfig/util.c     | 17 ++++++++++++++++-
…

You would like to use the function “strscpy” in these source files.

I miss some information so far.

1. Helpful change description
   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.18-rc2#n45

2. Nicer summary phrase

3. More appropriate recipient selection
   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.18-rc2#n231


…
> -- 
> ::DISCLAIMER::
…
> The 
> contents of this e-mail and any attachment(s) are confidential and
…

Please reconsider such hints once more for communication by the means of public mailing lists.
https://subspace.kernel.org/etiquette.html#do-not-include-confidentiality-disclaimers

Regards,
Markus