diff options
author | George Kadianakis <desnacked@gmail.com> | 2011-09-11 23:34:11 +0200 |
---|---|---|
committer | George Kadianakis <desnacked@gmail.com> | 2011-09-11 23:34:11 +0200 |
commit | c6811c57cb75b2c594b2a6fffaca0c5ae4c19e0a (patch) | |
tree | 3b60b2997c9153675e7f77861924c028caab4a02 /src | |
parent | 31361074216534b0a4c6377730c09b261ca4ef4e (diff) | |
download | tor-c6811c57cb75b2c594b2a6fffaca0c5ae4c19e0a.tar.gz tor-c6811c57cb75b2c594b2a6fffaca0c5ae4c19e0a.zip |
Enforce transport names being C identifiers.
Introduce string_is_C_identifier() and use it to enforce transport
names according to the 180 spec.
Diffstat (limited to 'src')
-rw-r--r-- | src/common/util.c | 28 | ||||
-rw-r--r-- | src/common/util.h | 2 | ||||
-rw-r--r-- | src/or/config.c | 8 | ||||
-rw-r--r-- | src/or/transports.c | 10 |
4 files changed, 48 insertions, 0 deletions
diff --git a/src/common/util.c b/src/common/util.c index 63172c36a3..5fc2cbeabc 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -719,6 +719,34 @@ find_str_at_start_of_line(const char *haystack, const char *needle) return NULL; } +/** Returns true if <b>string</b> could be a C identifier. + A C identifier must begin with a letter or an underscore and the + rest of its characters can be letters, numbers or underscores. No + length limit is imposed. */ +int +string_is_C_identifier(const char *string) +{ + size_t iter; + size_t length = strlen(string); + if (!length) + return 0; + + for (iter = 0; iter < length ; iter++) { + if (iter == 0) { + if (!(TOR_ISALPHA(string[iter]) || + string[iter] == '_')) + return 0; + } else { + if (!(TOR_ISALPHA(string[iter]) || + TOR_ISDIGIT(string[iter]) || + string[iter] == '_')) + return 0; + } + } + + return 1; +} + /** Return true iff the 'len' bytes at 'mem' are all zero. */ int tor_mem_is_zero(const char *mem, size_t len) diff --git a/src/common/util.h b/src/common/util.h index 7e889b10c7..04ae7cbc33 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -203,6 +203,8 @@ const char *find_whitespace(const char *s) ATTR_PURE; const char *find_whitespace_eos(const char *s, const char *eos) ATTR_PURE; const char *find_str_at_start_of_line(const char *haystack, const char *needle) ATTR_PURE; +int string_is_C_identifier(const char *string); + int tor_mem_is_zero(const char *mem, size_t len) ATTR_PURE; int tor_digest_is_zero(const char *digest) ATTR_PURE; int tor_digest256_is_zero(const char *digest) ATTR_PURE; diff --git a/src/or/config.c b/src/or/config.c index d36418b0d5..58668b1734 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -4724,6 +4724,10 @@ parse_client_transport_line(const char *line, int validate_only) } name = smartlist_get(items, 0); + if (!string_is_C_identifier(name)) { + log_warn(LD_CONFIG, "Transport name is not a C identifier (%s).", name); + goto err; + } /* field2 is either a SOCKS version or "exec" */ field2 = smartlist_get(items, 1); @@ -4826,6 +4830,10 @@ parse_server_transport_line(const char *line, int validate_only) } name = smartlist_get(items, 0); + if (!string_is_C_identifier(name)) { + log_warn(LD_CONFIG, "Transport name is not a C identifier (%s).", name); + goto err; + } type = smartlist_get(items, 1); diff --git a/src/or/transports.c b/src/or/transports.c index 1b7249fae2..6d1ddebe5d 100644 --- a/src/or/transports.c +++ b/src/or/transports.c @@ -686,6 +686,11 @@ parse_smethod_line(const char *line, managed_proxy_t *mp) tor_assert(!strcmp(smartlist_get(items,0),PROTO_SMETHOD)); method_name = smartlist_get(items,1); + if (!string_is_C_identifier(method_name)) { + log_warn(LD_CONFIG, "Transport name is not a C identifier (%s).", + method_name); + goto err; + } addrport = smartlist_get(items, 2); if (tor_addr_port_parse(addrport, &addr, &port)<0) { @@ -754,6 +759,11 @@ parse_cmethod_line(const char *line, managed_proxy_t *mp) tor_assert(!strcmp(smartlist_get(items,0),PROTO_CMETHOD)); method_name = smartlist_get(items,1); + if (!string_is_C_identifier(method_name)) { + log_warn(LD_CONFIG, "Transport name is not a C identifier (%s).", + method_name); + goto err; + } socks_ver_str = smartlist_get(items,2); |