[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Enforce transport names being C identifiers.



commit c6811c57cb75b2c594b2a6fffaca0c5ae4c19e0a
Author: George Kadianakis <desnacked@xxxxxxxxx>
Date:   Sun Sep 11 23:34:11 2011 +0200

    Enforce transport names being C identifiers.
    
    Introduce string_is_C_identifier() and use it to enforce transport
    names according to the 180 spec.
---
 src/common/util.c   |   28 ++++++++++++++++++++++++++++
 src/common/util.h   |    2 ++
 src/or/config.c     |    8 ++++++++
 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 63172c3..5fc2cbe 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 7e889b1..04ae7cb 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 d36418b..58668b1 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 1b7249f..6d1ddeb 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);
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits