[PATCH master 2/3] include: import Linux string_is_terminated helper

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

 



Some binary formats read by barebox feature null-terminated string.
Import the kernel's string_is_terminated() helper to verify such
strings before passing them to string API.

Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
---
 include/linux/string_helpers.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)
 create mode 100644 include/linux/string_helpers.h

diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h
new file mode 100644
index 000000000000..5a8a469be7c0
--- /dev/null
+++ b/include/linux/string_helpers.h
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_STRING_HELPERS_H_
+#define _LINUX_STRING_HELPERS_H_
+
+#include <linux/string.h>
+#include <linux/types.h>
+
+static inline bool string_is_terminated(const char *s, int len)
+{
+	return memchr(s, '\0', len) ? true : false;
+}
+
+#endif
-- 
2.39.2





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux