Loading src/common/util.c +4 −6 Original line number Diff line number Diff line Loading @@ -1223,17 +1223,15 @@ escaped(const char *s) return escaped_val_; } /** Escape every ";" or "\" character of <b>string</b>. Use * <b>escape_char</b> as the character to use for escaping. * The returned string is allocated on the heap and it's the * responsibility of the caller to free it. */ /** Escape every character of <b>string</b> that is in * <b>chars_to_escape</b>. The returned string is allocated on the * heap and it's the responsibility of the caller to free it. */ char * tor_escape_str_for_socks_arg(const char *string) tor_escape_str_for_socks_arg(const char *string, const char *chars_to_escape) { char *new_string = NULL; char *new_cp = NULL; size_t length, new_length; static const char *chars_to_escape = ";\\"; tor_assert(string); Loading src/common/util.h +2 −1 Original line number Diff line number Diff line Loading @@ -231,7 +231,8 @@ int tor_digest256_is_zero(const char *digest); char *esc_for_log(const char *string) ATTR_MALLOC; const char *escaped(const char *string); char *tor_escape_str_for_socks_arg(const char *string); char *tor_escape_str_for_socks_arg(const char *string, const char *chars_to_escape); struct smartlist_t; int tor_vsscanf(const char *buf, const char *pattern, va_list ap) \ Loading src/or/transports.c +1 −1 Original line number Diff line number Diff line Loading @@ -1440,7 +1440,7 @@ pt_stringify_socks_args(const smartlist_t *socks_args) SMARTLIST_FOREACH_BEGIN(socks_args, const char *, s) { /* Escape ';' and '\'. */ escaped_string = tor_escape_str_for_socks_arg(s); escaped_string = tor_escape_str_for_socks_arg(s, ";\\"); if (!escaped_string) goto done; Loading src/test/test_util.c +5 −5 Original line number Diff line number Diff line Loading @@ -803,30 +803,30 @@ test_util_escape_string_socks(void) char *escaped_string = NULL; /** Simple backslash escape. */ escaped_string = tor_escape_str_for_socks_arg("This is a backslash: \\"); escaped_string = tor_escape_str_for_socks_arg("This is a backslash: \\", ";\\"); test_assert(escaped_string); test_streq(escaped_string, "This is a backslash: \\\\"); tor_free(escaped_string); /** Simple semicolon escape. */ escaped_string = tor_escape_str_for_socks_arg("First rule: Do not use ;"); escaped_string = tor_escape_str_for_socks_arg("First rule: Do not use ;", ";\\"); test_assert(escaped_string); test_streq(escaped_string, "First rule: Do not use \\;"); tor_free(escaped_string); /** Empty string. */ escaped_string = tor_escape_str_for_socks_arg(""); escaped_string = tor_escape_str_for_socks_arg("", ";\\"); test_assert(escaped_string); test_streq(escaped_string, ""); tor_free(escaped_string); /** Escape all characters. */ escaped_string = tor_escape_str_for_socks_arg(";\\;\\"); escaped_string = tor_escape_str_for_socks_arg(";\\;\\", ";\\"); test_assert(escaped_string); test_streq(escaped_string, "\\;\\\\\\;\\\\"); tor_free(escaped_string); escaped_string = tor_escape_str_for_socks_arg(";"); escaped_string = tor_escape_str_for_socks_arg(";", ";\\"); test_assert(escaped_string); test_streq(escaped_string, "\\;"); tor_free(escaped_string); Loading Loading
src/common/util.c +4 −6 Original line number Diff line number Diff line Loading @@ -1223,17 +1223,15 @@ escaped(const char *s) return escaped_val_; } /** Escape every ";" or "\" character of <b>string</b>. Use * <b>escape_char</b> as the character to use for escaping. * The returned string is allocated on the heap and it's the * responsibility of the caller to free it. */ /** Escape every character of <b>string</b> that is in * <b>chars_to_escape</b>. The returned string is allocated on the * heap and it's the responsibility of the caller to free it. */ char * tor_escape_str_for_socks_arg(const char *string) tor_escape_str_for_socks_arg(const char *string, const char *chars_to_escape) { char *new_string = NULL; char *new_cp = NULL; size_t length, new_length; static const char *chars_to_escape = ";\\"; tor_assert(string); Loading
src/common/util.h +2 −1 Original line number Diff line number Diff line Loading @@ -231,7 +231,8 @@ int tor_digest256_is_zero(const char *digest); char *esc_for_log(const char *string) ATTR_MALLOC; const char *escaped(const char *string); char *tor_escape_str_for_socks_arg(const char *string); char *tor_escape_str_for_socks_arg(const char *string, const char *chars_to_escape); struct smartlist_t; int tor_vsscanf(const char *buf, const char *pattern, va_list ap) \ Loading
src/or/transports.c +1 −1 Original line number Diff line number Diff line Loading @@ -1440,7 +1440,7 @@ pt_stringify_socks_args(const smartlist_t *socks_args) SMARTLIST_FOREACH_BEGIN(socks_args, const char *, s) { /* Escape ';' and '\'. */ escaped_string = tor_escape_str_for_socks_arg(s); escaped_string = tor_escape_str_for_socks_arg(s, ";\\"); if (!escaped_string) goto done; Loading
src/test/test_util.c +5 −5 Original line number Diff line number Diff line Loading @@ -803,30 +803,30 @@ test_util_escape_string_socks(void) char *escaped_string = NULL; /** Simple backslash escape. */ escaped_string = tor_escape_str_for_socks_arg("This is a backslash: \\"); escaped_string = tor_escape_str_for_socks_arg("This is a backslash: \\", ";\\"); test_assert(escaped_string); test_streq(escaped_string, "This is a backslash: \\\\"); tor_free(escaped_string); /** Simple semicolon escape. */ escaped_string = tor_escape_str_for_socks_arg("First rule: Do not use ;"); escaped_string = tor_escape_str_for_socks_arg("First rule: Do not use ;", ";\\"); test_assert(escaped_string); test_streq(escaped_string, "First rule: Do not use \\;"); tor_free(escaped_string); /** Empty string. */ escaped_string = tor_escape_str_for_socks_arg(""); escaped_string = tor_escape_str_for_socks_arg("", ";\\"); test_assert(escaped_string); test_streq(escaped_string, ""); tor_free(escaped_string); /** Escape all characters. */ escaped_string = tor_escape_str_for_socks_arg(";\\;\\"); escaped_string = tor_escape_str_for_socks_arg(";\\;\\", ";\\"); test_assert(escaped_string); test_streq(escaped_string, "\\;\\\\\\;\\\\"); tor_free(escaped_string); escaped_string = tor_escape_str_for_socks_arg(";"); escaped_string = tor_escape_str_for_socks_arg(";", ";\\"); test_assert(escaped_string); test_streq(escaped_string, "\\;"); tor_free(escaped_string); Loading