Permalink
Browse files

Merge pull request #4 from ethankb/minor_fixes

Basically, just handling malformed content-length headers.
Instead of ethankb's exact solution, just catch ValueError
and log the invalid values.
  • Loading branch information...
1 parent 54c490d commit cb1e6a148db9dc7944b3f8f81b83589c05bc0b31 Andrew Fleenor committed Jul 13, 2012
Showing with 13 additions and 3 deletions.
  1. +13 −3 dpkt_http_replacement.py
  2. BIN tcp/.packet.py.swp
@@ -7,6 +7,7 @@
import cStringIO
import dpkt
+import logging
import settings
def parse_headers(f):
@@ -54,10 +55,19 @@ def parse_body(f, version, headers):
raise dpkt.NeedData('premature end of chunked body')
body = ''.join(l)
elif 'content-length' in headers:
- n = int(headers['content-length'])
+ # Ethan K B: Have observed malformed 0,0 content lengths
+ try:
+ n = int(headers['content-length'])
+ except ValueError:
+ logging.warn('HTTP content-length "%s" is invalid, assuming 0' %
+ headers['content-length'])
+ n = 0
body = f.read(n)
- if settings.strict_http_parse_body and len(body) != n:
- raise dpkt.NeedData('short body (missing %d bytes)' % (n - len(body)))
+ if len(body) != n:
+ logging.warn('HTTP content-length mismatch: expected %d, got %d', n,
+ len(body))
+ if settings.strict_http_parse_body:
+ raise dpkt.NeedData('short body (missing %d bytes)' % (n - len(body)))
else:
# XXX - need to handle HTTP/0.9
# BTW, this function is not called if status code is 204 or 304
View
Binary file not shown.

0 comments on commit cb1e6a1

Please sign in to comment.