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