[tor-commits] [obfsproxy/master] Some tweaks in Colin's fix to #9823.

asn at torproject.org asn at torproject.org
Wed Dec 31 15:30:08 UTC 2014


commit 64aeb8d880cf64eb22d80b3f07f97154c08a28ec
Author: George Kadianakis <desnacked at riseup.net>
Date:   Wed Dec 31 17:09:37 2014 +0200

    Some tweaks in Colin's fix to #9823.
    
    - Add a ChangeLog entry about this.
    - Don't catch exceptions of set_defaults().
    - Only catch explicit exceptions.
    - Kill trailing whitespace
---
 ChangeLog                     |    2 ++
 obfsproxy/pyobfsproxy.py      |   10 +++-------
 obfsproxy/transports/base.py  |    7 ++++---
 obfsproxy/transports/obfs2.py |    7 +++----
 4 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3107d2e..315c5f8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,8 @@ Changes in version 0.2.13 - UNRELEASED:
    when running in managed mode. Patch by Yawning Angel. Fixes #13587.
  - Make ScrambleSuit servers cache the HMAC of their own UniformDH messages.
    Fixes #14038.
+ - Improve handling of failures during command line parsing.
+   Patch by Colin Teberg. Fixes #9823.
 
 
 Changes in version 0.2.12 - 2014-07-22:
diff --git a/obfsproxy/pyobfsproxy.py b/obfsproxy/pyobfsproxy.py
index 4a3ca83..4a2faf6 100755
--- a/obfsproxy/pyobfsproxy.py
+++ b/obfsproxy/pyobfsproxy.py
@@ -66,11 +66,7 @@ def set_up_cli_parsing():
     for transport, transport_class in transports.transports.items():
         subparser = subparsers.add_parser(transport, help='%s help' % transport)
         transport_class['base'].register_external_mode_cli(subparser)
-        try:
-            subparser.set_defaults(validation_function=transport_class['base'].validate_external_mode_cli)
-        except ValueError, err:
-            log.error(err)
-            sys.exit(1)
+        subparser.set_defaults(validation_function=transport_class['base'].validate_external_mode_cli)
 
     return parser
 
@@ -182,9 +178,9 @@ def pyobfsproxy():
         # they can initialize and setup themselves. Exit if the
         # provided arguments were corrupted.
 
-        try: 
+        try:
             args.validation_function(args)
-        except Exception, err:
+        except ValueError, err:
             log.error(err)
             sys.exit(1)
 
diff --git a/obfsproxy/transports/base.py b/obfsproxy/transports/base.py
index ae1d13b..f4379e4 100644
--- a/obfsproxy/transports/base.py
+++ b/obfsproxy/transports/base.py
@@ -136,6 +136,7 @@ class BaseTransport(object):
 
         Override for your own needs.
         """
+        err = None
 
         # If we are not 'socks', we need to have a static destination
         # to send our data to.
@@ -148,10 +149,10 @@ class BaseTransport(object):
         elif (args.mode == 'ext_server') and (not args.ext_cookie_file):
             err = "You need to specify --ext-cookie-file as an ext_server."
 
-        try:
-            raise argparse.ArgumentTypeError(err)
-        except NameError:
+        if not err: # We didn't encounter any errors during validation
             return True
+        else: # Ugh, something failed.
+            raise ValueError(err)
 
 class PluggableTransportError(Exception): pass
 class SOCKSArgsError(Exception): pass
diff --git a/obfsproxy/transports/obfs2.py b/obfsproxy/transports/obfs2.py
index c77c5cd..cd5e2a8 100644
--- a/obfsproxy/transports/obfs2.py
+++ b/obfsproxy/transports/obfs2.py
@@ -8,6 +8,7 @@ The obfs2 module implements the obfs2 protocol.
 import random
 import hashlib
 import argparse
+import sys
 
 import obfsproxy.common.aes as aes
 import obfsproxy.common.serialize as srlz
@@ -126,12 +127,12 @@ class Obfs2Transport(base.BaseTransport):
         if args.ss_hash_iterations:
             cls.ss_hash_iterations = args.ss_hash_iterations
 
-        try: 
+        try:
             super(Obfs2Transport, cls).validate_external_mode_cli(args)
         except ValueError, err:
             log.error(err)
             sys.exit(1)
-            
+
     def handle_socks_args(self, args):
         log.debug("obfs2: Got '%s' as SOCKS arguments." % args)
 
@@ -321,5 +322,3 @@ class Obfs2Server(Obfs2Transport):
         self.recv_keytype = "Initiator obfuscated data"
 
         Obfs2Transport.__init__(self)
-
-



More information about the tor-commits mailing list