# Buggy code
def m2i(self, pkt, m):
    s = pkt.tls_session
    tmp_len = self.length_from(pkt)
    if s.prcs:
        cls = s.prcs.key_exchange.server_kx_msg_cls(m)
        if cls is None:
            return None, Raw(m[:tmp_len]) / Padding(m[tmp_len:])
        return cls(m, tls_session=s)
    else:
        try:
            p = ServerDHParams(m, tls_session=s)
            if pkcs_os2ip(p.load[:2]) not in _tls_hash_sig:
                raise Exception
            return p
        except Exception:
            cls = _tls_server_ecdh_cls_guess(m)
            p = cls(m, tls_session=s)
            if pkcs_os2ip(p.load[:2]) not in _tls_hash_sig:
                return None, Raw(m[:tmp_len]) / Padding(m[tmp_len:])
            return p


# Traceback (TypeError)
Traceback (most recent call last):
File "utils/poc.py", line 51, in <module>
test_failed_fn()
File "utils/poc.py", line 47, in test_failed_fn
extract_tls_payloads(os.path.join(data_root, fn), 900)
File "utils/poc.py", line 19, in extract_tls_payloads
payload = bytes(p[TLS])
File "/data1/wangqian/venv_py3/lib/python3.7/site-packages/scapy/layers/tls/session.py", line 966, in __bytes__
built_packet = super(_GenericTLSSessionInheritance, self).__bytes__()
File "/data1/wangqian/venv_py3/lib/python3.7/site-packages/scapy/packet.py", line 492, in __bytes__
return self.build()
File "/data1/wangqian/venv_py3/lib/python3.7/site-packages/scapy/packet.py", line 612, in build
p = self.do_build()
File "/data1/wangqian/venv_py3/lib/python3.7/site-packages/scapy/packet.py", line 594, in do_build
pkt = self.self_build()
File "/data1/wangqian/venv_py3/lib/python3.7/site-packages/scapy/packet.py", line 575, in self_build
p = f.addfield(self, p, val)
File "/data1/wangqian/venv_py3/lib/python3.7/site-packages/scapy/layers/tls/record.py", line 207, in addfield
res += self.i2m(pkt, p)
File "/data1/wangqian/venv_py3/lib/python3.7/site-packages/scapy/layers/tls/record.py", line 194, in i2m
cur = raw(p)
File "/data1/wangqian/venv_py3/lib/python3.7/site-packages/scapy/compat.py", line 53, in raw
return bytes(x)
File "/data1/wangqian/venv_py3/lib/python3.7/site-packages/scapy/layers/tls/session.py", line 966, in __bytes__
built_packet = super(_GenericTLSSessionInheritance, self).__bytes__()
File "/data1/wangqian/venv_py3/lib/python3.7/site-packages/scapy/packet.py", line 492, in __bytes__
return self.build()
File "/data1/wangqian/venv_py3/lib/python3.7/site-packages/scapy/layers/tls/handshake.py", line 1028, in build
m = s.client_random + s.server_random + raw(p)
File "/data1/wangqian/venv_py3/lib/python3.7/site-packages/scapy/compat.py", line 53, in raw
return bytes(x)
TypeError: 'NoneType' object cannot be interpreted as an integer

# Fixed code
def m2i(self, pkt, m):
    s = pkt.tls_session
    tmp_len = self.length_from(pkt)
    if s.prcs:
        cls = s.prcs.key_exchange.server_kx_msg_cls(m)
        if cls is None:
            return Raw(m[:tmp_len]) / Padding(m[tmp_len:])
        return cls(m, tls_session=s)
    else:
        try:
            p = ServerDHParams(m, tls_session=s)
            if pkcs_os2ip(p.load[:2]) not in _tls_hash_sig:
                raise Exception
            return p
        except Exception:
            cls = _tls_server_ecdh_cls_guess(m)
            p = cls(m, tls_session=s)
            if pkcs_os2ip(p.load[:2]) not in _tls_hash_sig:
                return Raw(m[:tmp_len]) / Padding(m[tmp_len:])
            return p