mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-25 15:10:48 +01:00
Rename tor_escape_str_for_socks_arg() to something more generic.
Since we are going to be using that function to also escape parameters passed to transport proxies using environment variables.
This commit is contained in:
parent
ea72958f25
commit
1a0cf08841
4 changed files with 11 additions and 11 deletions
|
@ -1227,7 +1227,7 @@ escaped(const char *s)
|
||||||
* <b>chars_to_escape</b>. The returned string is allocated on the
|
* <b>chars_to_escape</b>. The returned string is allocated on the
|
||||||
* heap and it's the responsibility of the caller to free it. */
|
* heap and it's the responsibility of the caller to free it. */
|
||||||
char *
|
char *
|
||||||
tor_escape_str_for_socks_arg(const char *string, const char *chars_to_escape)
|
tor_escape_str_for_pt_args(const char *string, const char *chars_to_escape)
|
||||||
{
|
{
|
||||||
char *new_string = NULL;
|
char *new_string = NULL;
|
||||||
char *new_cp = NULL;
|
char *new_cp = NULL;
|
||||||
|
|
|
@ -231,8 +231,8 @@ int tor_digest256_is_zero(const char *digest);
|
||||||
char *esc_for_log(const char *string) ATTR_MALLOC;
|
char *esc_for_log(const char *string) ATTR_MALLOC;
|
||||||
const char *escaped(const char *string);
|
const char *escaped(const char *string);
|
||||||
|
|
||||||
char *tor_escape_str_for_socks_arg(const char *string,
|
char *tor_escape_str_for_pt_args(const char *string,
|
||||||
const char *chars_to_escape);
|
const char *chars_to_escape);
|
||||||
|
|
||||||
struct smartlist_t;
|
struct smartlist_t;
|
||||||
int tor_vsscanf(const char *buf, const char *pattern, va_list ap) \
|
int tor_vsscanf(const char *buf, const char *pattern, va_list ap) \
|
||||||
|
|
|
@ -1440,7 +1440,7 @@ pt_stringify_socks_args(const smartlist_t *socks_args)
|
||||||
|
|
||||||
SMARTLIST_FOREACH_BEGIN(socks_args, const char *, s) {
|
SMARTLIST_FOREACH_BEGIN(socks_args, const char *, s) {
|
||||||
/* Escape ';' and '\'. */
|
/* Escape ';' and '\'. */
|
||||||
escaped_string = tor_escape_str_for_socks_arg(s, ";\\");
|
escaped_string = tor_escape_str_for_pt_args(s, ";\\");
|
||||||
if (!escaped_string)
|
if (!escaped_string)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
|
|
|
@ -796,37 +796,37 @@ test_util_expand_filename(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** Test tor_escape_str_for_socks_arg(). */
|
/** Test tor_escape_str_for_pt_args(). */
|
||||||
static void
|
static void
|
||||||
test_util_escape_string_socks(void)
|
test_util_escape_string_socks(void)
|
||||||
{
|
{
|
||||||
char *escaped_string = NULL;
|
char *escaped_string = NULL;
|
||||||
|
|
||||||
/** Simple backslash escape. */
|
/** Simple backslash escape. */
|
||||||
escaped_string = tor_escape_str_for_socks_arg("This is a backslash: \\", ";\\");
|
escaped_string = tor_escape_str_for_pt_args("This is a backslash: \\",";\\");
|
||||||
test_assert(escaped_string);
|
test_assert(escaped_string);
|
||||||
test_streq(escaped_string, "This is a backslash: \\\\");
|
test_streq(escaped_string, "This is a backslash: \\\\");
|
||||||
tor_free(escaped_string);
|
tor_free(escaped_string);
|
||||||
|
|
||||||
/** Simple semicolon escape. */
|
/** Simple semicolon escape. */
|
||||||
escaped_string = tor_escape_str_for_socks_arg("First rule: Do not use ;", ";\\");
|
escaped_string = tor_escape_str_for_pt_args("First rule:Do not use ;",";\\");
|
||||||
test_assert(escaped_string);
|
test_assert(escaped_string);
|
||||||
test_streq(escaped_string, "First rule: Do not use \\;");
|
test_streq(escaped_string, "First rule:Do not use \\;");
|
||||||
tor_free(escaped_string);
|
tor_free(escaped_string);
|
||||||
|
|
||||||
/** Empty string. */
|
/** Empty string. */
|
||||||
escaped_string = tor_escape_str_for_socks_arg("", ";\\");
|
escaped_string = tor_escape_str_for_pt_args("", ";\\");
|
||||||
test_assert(escaped_string);
|
test_assert(escaped_string);
|
||||||
test_streq(escaped_string, "");
|
test_streq(escaped_string, "");
|
||||||
tor_free(escaped_string);
|
tor_free(escaped_string);
|
||||||
|
|
||||||
/** Escape all characters. */
|
/** Escape all characters. */
|
||||||
escaped_string = tor_escape_str_for_socks_arg(";\\;\\", ";\\");
|
escaped_string = tor_escape_str_for_pt_args(";\\;\\", ";\\");
|
||||||
test_assert(escaped_string);
|
test_assert(escaped_string);
|
||||||
test_streq(escaped_string, "\\;\\\\\\;\\\\");
|
test_streq(escaped_string, "\\;\\\\\\;\\\\");
|
||||||
tor_free(escaped_string);
|
tor_free(escaped_string);
|
||||||
|
|
||||||
escaped_string = tor_escape_str_for_socks_arg(";", ";\\");
|
escaped_string = tor_escape_str_for_pt_args(";", ";\\");
|
||||||
test_assert(escaped_string);
|
test_assert(escaped_string);
|
||||||
test_streq(escaped_string, "\\;");
|
test_streq(escaped_string, "\\;");
|
||||||
tor_free(escaped_string);
|
tor_free(escaped_string);
|
||||||
|
|
Loading…
Add table
Reference in a new issue