commit ee63d3fa345ed7230d229433416e75d4c43d7436 Author: George Kadianakis desnacked@riseup.net Date: Wed Apr 11 22:31:30 2012 +0200
Fix obfs2 argument parsing.
Keep a count of how many command line arguments we have left, so that we know when to stop parsing. --- ChangeLog | 5 +++++ src/protocols/obfs2.c | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletions(-)
diff --git a/ChangeLog b/ChangeLog index 2a7605c..ae2ee92 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Changes in version 0.1.4 - <not yet released> + - Fix crash when parsing obfs2 command line arguments. Fixes bug + #5141. + + Changes in version 0.1.3 - 2012-04-03 - Display git revision when we start logging. Fixes part of bug #5157. diff --git a/src/protocols/obfs2.c b/src/protocols/obfs2.c index 59c3d55..566c2ed 100644 --- a/src/protocols/obfs2.c +++ b/src/protocols/obfs2.c @@ -167,6 +167,7 @@ int parse_and_set_options(int n_options, const char *const *options, obfs2_config_t *cfg) { + int options_left = n_options; int got_dest=0; int got_ss=0; const char* defport; @@ -177,7 +178,7 @@ parse_and_set_options(int n_options, const char *const *options, }
/* Now parse the optional arguments */ - while (!strncmp(*options,"--",2)) { + while (options_left && !strncmp(*options,"--",2)) { if (!strncmp(*options,"--dest=",7)) { if (got_dest) return -1; @@ -201,9 +202,17 @@ parse_and_set_options(int n_options, const char *const *options, log_warn("obfs2: Unknown argument '%s'.", *options); return -1; } + options_left--; options++; }
+ /* we still need to parse the mode and the listen address. */ + if (options_left != 2) { + log_warn("obfs2 needs two options (mode, listen address), after its " + "optional arguments. You provided %d.", options_left); + return -1; + } + if (!strcmp(*options, "client")) { defport = "48988"; /* bf5c */ cfg->mode = LSN_SIMPLE_CLIENT;
tor-commits@lists.torproject.org