Opened 5 years ago

Closed 5 years ago

#11329 closed defect (fixed)

struct.unpack() bug in socks5.py:get_uint16()

Reported by: asn Owned by: asn
Priority: Medium Milestone:
Component: Archived/Obfsproxy Version:
Severity: Keywords:
Cc: Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description

Apparently we are passing a bytearray to struct.unpack() and it doesn't like it. I got stuff like:

  File "/usr/local/lib/python2.7/dist-packages/obfsproxy-0.2.7_dirty-py2.7.egg/obfsproxy/network/socks5.py", line 319, in processNoAuthRequired
    self.processRequest()
  File "/usr/local/lib/python2.7/dist-packages/obfsproxy-0.2.7_dirty-py2.7.egg/obfsproxy/network/socks5.py", line 377, in processRequest
    port = msg.get_uint16(True)
  File "/usr/local/lib/python2.7/dist-packages/obfsproxy-0.2.7_dirty-py2.7.egg/obfsproxy/network/socks5.py", line 503, in get_uint16
    ret = struct.unpack("!H", self[0:2])[0]
struct.error: unpack requires a string argument of length 2

I then checked the length of self[0:2] and indeed it was 2. Then I checked it's type and it was a bytearray. I casted the bytearray to a str before passing it to struct.unpack and it seemed to fix the problem.

I'm not sure why we didn't trigger this bug in the past.
The bug is included in the latest obfsproxy-0.2.7 release, I think.

Child Tickets

Change History (3)

comment:1 Changed 5 years ago by yawning

This is dependent on the version of python: http://bugs.python.org/issue10212

I did all the development with 2.7.6 so I didn't hit it. Casting is the correct thing to do, want me to fix this in a branch?

comment:2 Changed 5 years ago by yawning

Status: newneeds_review

comment:3 Changed 5 years ago by asn

Resolution: fixed
Status: needs_reviewclosed

Fixed. Thanks!

Note: See TracTickets for help on using tickets.