[PATCH 36/74] backports: support strscpy_pad in older kernels

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

 



From: Miri Korenblit <miriam.rachel.korenblit@xxxxxxxxx>

This was added in kernel v5.2. Add support for it in older kernels.

Signed-off-by: Miri Korenblit <miriam.rachel.korenblit@xxxxxxxxx>
Signed-off-by: Johannes Berg <johannes.berg@xxxxxxxxx>
---
 backport/backport-include/linux/string.h |  5 +++++
 backport/compat/backport-5.2.c           | 14 ++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/backport/backport-include/linux/string.h b/backport/backport-include/linux/string.h
index ce4c99e34e0d..f6e6cdcf08b8 100644
--- a/backport/backport-include/linux/string.h
+++ b/backport/backport-include/linux/string.h
@@ -23,4 +23,9 @@
 })
 #endif
 
+#if LINUX_VERSION_IS_LESS(5,2,0)
+#define strscpy_pad LINUX_BACKPORT(strscpy_pad)
+ssize_t strscpy_pad(char *dest, const char *src, size_t count);
+#endif
+
 #endif /* __BACKPORT_LINUX_STRING_H */
diff --git a/backport/compat/backport-5.2.c b/backport/compat/backport-5.2.c
index 5624d5fa08e5..581bb9cfe7fd 100644
--- a/backport/compat/backport-5.2.c
+++ b/backport/compat/backport-5.2.c
@@ -479,3 +479,17 @@ int __nla_parse(struct nlattr **tb, int maxtype,
 				    extack, tb);
 }
 EXPORT_SYMBOL(__nla_parse);
+
+ssize_t strscpy_pad(char *dest, const char *src, size_t count)
+{
+	ssize_t written;
+
+	written = strscpy(dest, src, count);
+	if (written < 0 || written == count - 1)
+		return written;
+
+	memset(dest + written + 1, 0, count - written - 1);
+
+	return written;
+}
+EXPORT_SYMBOL(strscpy_pad);
-- 
2.45.1





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

  Powered by Linux