diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/util.c | 14 | ||||
-rw-r--r-- | src/common/util.h | 1 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/common/util.c b/src/common/util.c index be866a5fe6..442d57a2cf 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -1381,6 +1381,20 @@ esc_for_log(const char *s) return result; } +/** Similar to esc_for_log. Allocate and return a new string representing + * the first n characters in <b>chars</b>, surround by quotes and using + * standard C escapes. If a NUL character is encountered in <b>chars</b>, + * the resulting string will be terminated there. + */ +char * +esc_for_log_len(const char *chars, size_t n) +{ + char *string = tor_strndup(chars, n); + char *string_escaped = esc_for_log(string); + tor_free(string); + return string_escaped; +} + /** Allocate and return a new string representing the contents of <b>s</b>, * surrounded by quotes and using standard C escapes. * diff --git a/src/common/util.h b/src/common/util.h index 89c140032a..175a078c6b 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -239,6 +239,7 @@ int tor_mem_is_zero(const char *mem, size_t len); int tor_digest_is_zero(const char *digest); int tor_digest256_is_zero(const char *digest); char *esc_for_log(const char *string) ATTR_MALLOC; +char *esc_for_log_len(const char *chars, size_t n) ATTR_MALLOC; const char *escaped(const char *string); char *tor_escape_str_for_pt_args(const char *string, |