The patch titled Subject: lib/string_helpers: allow to append additional characters to be escaped has been added to the -mm tree. Its filename is lib-string_helpers-allow-to-append-additional-characters-to-be-escaped.patch This patch should soon appear at https://ozlabs.org/~akpm/mmots/broken-out/lib-string_helpers-allow-to-append-additional-characters-to-be-escaped.patch and later at https://ozlabs.org/~akpm/mmotm/broken-out/lib-string_helpers-allow-to-append-additional-characters-to-be-escaped.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx> Subject: lib/string_helpers: allow to append additional characters to be escaped Introduce a new flag to append additional characters, passed in 'only' parameter, to be escaped if they fall in the corresponding class. Link: https://lkml.kernel.org/r/20210504180819.73127-7-andriy.shevchenko@xxxxxxxxxxxxxxx Signed-off-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx> Cc: Alexander Viro <viro@xxxxxxxxxxxxxxxxxx> Cc: Chuck Lever <chuck.lever@xxxxxxxxxx> Cc: "J. Bruce Fields" <bfields@xxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- include/linux/string_helpers.h | 1 + lib/string_helpers.c | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) --- a/include/linux/string_helpers.h~lib-string_helpers-allow-to-append-additional-characters-to-be-escaped +++ a/include/linux/string_helpers.h @@ -54,6 +54,7 @@ static inline int string_unescape_any_in #define ESCAPE_HEX BIT(5) #define ESCAPE_NA BIT(6) #define ESCAPE_NAP BIT(7) +#define ESCAPE_APPEND BIT(8) int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, unsigned int flags, const char *only); --- a/lib/string_helpers.c~lib-string_helpers-allow-to-append-additional-characters-to-be-escaped +++ a/lib/string_helpers.c @@ -493,6 +493,11 @@ static bool escape_hex(unsigned char c, * escape only non-ascii characters, checked by isascii() * %ESCAPE_NAP: * escape only non-printable or non-ascii characters + * %ESCAPE_APPEND: + * append characters from @only to be escaped by the given classes + * + * %ESCAPE_APPEND would help to pass additional characters to the escaped, when + * one of %ESCAPE_NP, %ESCAPE_NA, or %ESCAPE_NAP is provided. * * One notable caveat, the %ESCAPE_NAP, %ESCAPE_NP and %ESCAPE_NA have the * higher priority than the rest of the flags (%ESCAPE_NAP is the highest). @@ -513,9 +518,11 @@ int string_escape_mem(const char *src, s char *p = dst; char *end = p + osz; bool is_dict = only && *only; + bool is_append = flags & ESCAPE_APPEND; while (isz--) { unsigned char c = *src++; + bool in_dict = is_dict && strchr(only, c); /* * Apply rules in the following sequence: @@ -531,20 +538,24 @@ int string_escape_mem(const char *src, s * defined by given @flags * In these cases we just pass through a character to the * output buffer. + * + * When %ESCAPE_APPEND is passed, the characters from @only + * have been excluded from the %ESCAPE_NAP, %ESCAPE_NP, and + * %ESCAPE_NA cases. */ - if (is_dict && !strchr(only, c) && + if (!(is_append || in_dict) && is_dict && escape_passthrough(c, &p, end)) continue; - if (isascii(c) && isprint(c) && + if (!(is_append && in_dict) && isascii(c) && isprint(c) && flags & ESCAPE_NAP && escape_passthrough(c, &p, end)) continue; - if (isprint(c) && + if (!(is_append && in_dict) && isprint(c) && flags & ESCAPE_NP && escape_passthrough(c, &p, end)) continue; - if (isascii(c) && + if (!(is_append && in_dict) && isascii(c) && flags & ESCAPE_NA && escape_passthrough(c, &p, end)) continue; _ Patches currently in -mm which might be from andriy.shevchenko@xxxxxxxxxxxxxxx are lib-string_helpers-switch-to-use-bit-macro.patch lib-string_helpers-move-escape_np-check-inside-else-branch-in-a-loop.patch lib-string_helpers-drop-indentation-level-in-string_escape_mem.patch lib-string_helpers-introduce-escape_na-for-escaping-non-ascii.patch lib-string_helpers-introduce-escape_nap-to-escape-non-ascii-and-non-printable.patch lib-string_helpers-allow-to-append-additional-characters-to-be-escaped.patch lib-test-string_helpers-print-flags-in-hexadecimal-format.patch lib-test-string_helpers-get-rid-of-trailing-comma-in-terminators.patch lib-test-string_helpers-add-test-cases-for-new-features.patch maintainers-add-myself-as-designated-reviewer-for-generic-string-library.patch seq_file-introduce-seq_escape_mem.patch seq_file-add-seq_escape_str-as-replica-of-string_escape_str.patch seq_file-convert-seq_escape-to-use-seq_escape_str.patch nfsd-avoid-non-flexible-api-in-seq_quote_mem.patch seq_file-drop-unused-_escape_mem_ascii.patch