diff options
Diffstat (limited to 'lib/string_helpers.c')
-rw-r--r-- | lib/string_helpers.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/string_helpers.c b/lib/string_helpers.c index 4403e1924f73..3a90a9e2b94a 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c | |||
@@ -540,6 +540,25 @@ int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, | |||
540 | } | 540 | } |
541 | EXPORT_SYMBOL(string_escape_mem); | 541 | EXPORT_SYMBOL(string_escape_mem); |
542 | 542 | ||
543 | int string_escape_mem_ascii(const char *src, size_t isz, char *dst, | ||
544 | size_t osz) | ||
545 | { | ||
546 | char *p = dst; | ||
547 | char *end = p + osz; | ||
548 | |||
549 | while (isz--) { | ||
550 | unsigned char c = *src++; | ||
551 | |||
552 | if (!isprint(c) || !isascii(c) || c == '"' || c == '\\') | ||
553 | escape_hex(c, &p, end); | ||
554 | else | ||
555 | escape_passthrough(c, &p, end); | ||
556 | } | ||
557 | |||
558 | return p - dst; | ||
559 | } | ||
560 | EXPORT_SYMBOL(string_escape_mem_ascii); | ||
561 | |||
543 | /* | 562 | /* |
544 | * Return an allocated string that has been escaped of special characters | 563 | * Return an allocated string that has been escaped of special characters |
545 | * and double quotes, making it safe to log in quotes. | 564 | * and double quotes, making it safe to log in quotes. |