diff options
author | George Kadianakis <desnacked@riseup.net> | 2012-06-29 19:32:34 +0300 |
---|---|---|
committer | George Kadianakis <desnacked@riseup.net> | 2012-09-05 18:23:28 +0300 |
commit | 44fe717524408d247ab10e3794438232d81d66dc (patch) | |
tree | 51c23d566b2812aeeac0e24bfad88fecfa8d7159 /src/common | |
parent | 443260ffd8370c0fddefad42479b957132e8d275 (diff) | |
download | tor-44fe717524408d247ab10e3794438232d81d66dc.tar tor-44fe717524408d247ab10e3794438232d81d66dc.tar.gz |
General tweaks and fixes for Nick's comments.
* Add changes/ files.
* Edit the tor-fw-helper manpage.
* Fix check-spaces.
* Add prototype for get_list_of_ports_to_forward().
* Fix tor_parse_long() TCP port range.
* Improve doc. of tor_check_port_forwarding().
* Check for overflows in tor_check_port_forwarding().
* Demote successful port forwarding to LOG_INFO.
Conflicts:
src/common/address.c
src/or/circuitbuild.c
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/address.c | 1 | ||||
-rw-r--r-- | src/common/util.c | 42 |
2 files changed, 31 insertions, 12 deletions
diff --git a/src/common/address.c b/src/common/address.c index e5862be1e..ac45cba95 100644 --- a/src/common/address.c +++ b/src/common/address.c @@ -1697,7 +1697,6 @@ tor_addr_hostname_is_local(const char *name) !strcasecmpend(name, ".local"); } - /** Return a newly allocated tor_addr_port_t with <b>addr</b> and <b>port</b> filled in. */ tor_addr_port_t * diff --git a/src/common/util.c b/src/common/util.c index b1a05b576..25ddcc1fb 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -4676,10 +4676,10 @@ handle_fw_helper_line(const char *line) message_for_log ? message_for_log : "", internal_port); } else { - log_notice(LD_GENERAL, - "Tor successfully forwarded TCP port '%s' to '%s'%s.", - external_port, internal_port, - message_for_log ? message_for_log : ""); + log_info(LD_GENERAL, + "Tor successfully forwarded TCP port '%s' to '%s'%s.", + external_port, internal_port, + message_for_log ? message_for_log : ""); } goto done; @@ -4723,7 +4723,9 @@ handle_fw_helper_output(process_handle_t *process_handle) } /** Spawn tor-fw-helper and ask it to forward the ports in - * <b>ports_to_forward</b>. */ + * <b>ports_to_forward</b>. <b>ports_to_forward</b> contains strings + * of the form "<external port>:<internal port>", which is the format + * that tor-fw-helper expects. */ void tor_check_port_forwarding(const char *filename, smartlist_t *ports_to_forward, @@ -4748,17 +4750,35 @@ tor_check_port_forwarding(const char *filename, /* Start the child, if it is not already running */ if ((!child_handle || child_handle->status != PROCESS_STATUS_RUNNING) && time_to_run_helper < now) { - /* tor-fw-helper cli looks like this: tor_fw_helper -p :5555 -p 4555:1111 */ + /*tor-fw-helper cli looks like this: tor_fw_helper -p :5555 -p 4555:1111 */ const char **argv; /* cli arguments */ - /* Number of cli arguments: one for the filename, two for each - smartlist element (one for "-p" and one for the ports), and one - for the final NULL. */ - int args_n = 1 + 2*smartlist_len(ports_to_forward) + 1; + int args_n, status; int argv_index = 0; /* index inside 'argv' */ - int status; tor_assert(smartlist_len(ports_to_forward) > 0); + /* check for overflow during 'argv' allocation: + (len(ports_to_forward)*2 + 2)*sizeof(char*) > SIZE_MAX == + len(ports_to_forward) > (((SIZE_MAX/sizeof(char*)) - 2)/2) */ + if ((size_t) smartlist_len(ports_to_forward) > + (((SIZE_MAX/sizeof(char*)) - 2)/2)) { + log_warn(LD_GENERAL, + "Overflow during argv allocation. This shouldn't happen."); + return; + } + /* check for overflow during 'argv_index' increase: + ((len(ports_to_forward)*2 + 2) > INT_MAX) == + len(ports_to_forward) > (INT_MAX - 2)/2 */ + if (smartlist_len(ports_to_forward) > (INT_MAX - 2)/2) { + log_warn(LD_GENERAL, + "Overflow during argv_index increase. This shouldn't happen."); + return; + } + + /* Calculate number of cli arguments: one for the filename, two + for each smartlist element (one for "-p" and one for the + ports), and one for the final NULL. */ + args_n = 1 + 2*smartlist_len(ports_to_forward) + 1; argv = tor_malloc_zero(sizeof(char*)*args_n); argv[argv_index++] = filename; |