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

Biancaa Ramesh posted 1 patch 13 hours 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 13 hours 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 Markus Elfring 11 hours 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