From a6e2c2f3cb498a30a3bf42b82419ad20a5cc3045 Mon Sep 17 00:00:00 2001
From: Pierre LALET <pierre.lalet@cea.fr>
Date: Wed, 22 Mar 2017 08:24:44 +0100
Subject: [PATCH] Prevent sr() tests crashes

---
 scapy/contrib/HomePlugAV.uts |  9 +++++++++
 test/edns0.uts               |  6 ++++++
 test/regression.uts          | 11 ++++++++++-
 3 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/scapy/contrib/HomePlugAV.uts b/scapy/contrib/HomePlugAV.uts
index 0982e97e..815390c0 100644
--- a/scapy/contrib/HomePlugAV.uts
+++ b/scapy/contrib/HomePlugAV.uts
@@ -85,18 +85,27 @@ _ == (True, True)
 #= Discovery packet tests in local
 #~ netaccess HomePlugAV NetworkInfoConfirmationV10 NetworkInfoConfirmationV11
 #pkt = Ether()/HomePlugAV()
+#old_debug_dissector = conf.debug_dissector
+#conf.debug_dissector = False
 #a = srp1(pkt, iface="eth0")
+#conf.debug_dissector = old_debug_dissector
 #a
 #pkt.version = a.version
 #pkt /= NetworkInformationRequest()
+#old_debug_dissector = conf.debug_dissector
+#conf.debug_dissector = False
 #a = srp1(pkt, iface="eth0")
+#conf.debug_dissector = old_debug_dissector
 #NetworkInfoConfirmationV10 in a or NetworkInfoConfirmationV11 in a
 #_ == True
 
 #= Reading local 0x400st octets of Software Image in Module Data blocks
 #~ netaccess HomePlugAV ReadModuleDataRequest
 #pkt = Ether()/HomePlugAV()/ReadModuleDataRequest(ModuleID=0x1)
+#old_debug_dissector = conf.debug_dissector
+#conf.debug_dissector = False
 #a = srp1(pkt, iface="eth0")
+#conf.debug_dissector = old_debug_dissector
 #a
 #len(a.ModuleData) == pkt.Length
 #_ == True
diff --git a/test/edns0.uts b/test/edns0.uts
index 0fcbca06..927ccd6e 100644
--- a/test/edns0.uts
+++ b/test/edns0.uts
@@ -48,7 +48,10 @@ str(tlv) == b'\x00\x05\x00\x04\x00\x11"3'
 #= EDNS-PING - Live test
 #~ netaccess
 #* NB: 85.17.219.217 and www.edns-ping.org seem down
+#old_debug_dissector = conf.debug_dissector
+#conf.debug_dissector = False
 #r = sr1(IP(dst="85.17.219.217")/UDP()/DNS(qd=[DNSQR(qtype="A", qname="www.edns-ping.org.")], ar=[DNSRROPT(z=0, rdata=[EDNS0TLV(optcode="PING", optdata=b"\x00\x11\x22\x33")])]), timeout=1)
+#conf.debug_dissector = old_debug_dissector
 #len(r.ar) and r.ar.rdata[0].optcode == 4  # XXX: should be 5
 
 + Test DNS Name Server Identifier (NSID) Option
@@ -59,5 +62,8 @@ str(tlv) == b'\x00\x02\x00\x00'
 
 = NSID - Live test
 ~ netaccess
+old_debug_dissector = conf.debug_dissector
+conf.debug_dissector = False
 r = sr1(IP(dst="l.root-servers.net")/UDP()/DNS(qd=[DNSQR(qtype="SOA", qname=".")], ar=[DNSRROPT(z=0, rdata=[EDNS0TLV(optcode="NSID")])]), timeout=1)
+conf.debug_dissector = old_debug_dissector
 len(r.ar) and DNSRROPT in r.ar and len(r.ar[DNSRROPT].rdata) and len([x for x in r.ar[DNSRROPT].rdata if x.optcode == 3])
diff --git a/test/regression.uts b/test/regression.uts
index 5bc959b4..be34b65d 100644
--- a/test/regression.uts
+++ b/test/regression.uts
@@ -491,7 +491,10 @@ assert(x.PDU.varbindlist[2].value == 1)
 
 = Sending and receiving an ICMP
 ~ netaccess IP ICMP
-x=sr1(IP(dst="www.google.com")/ICMP(),timeout=3)
+old_debug_dissector = conf.debug_dissector
+conf.debug_dissector = False
+x = sr1(IP(dst="www.google.com")/ICMP(),timeout=3)
+conf.debug_dissector = old_debug_dissector
 x
 assert x[IP].ottl() in [32, 64, 128, 255]
 assert 0 <= x[IP].hops() <= 126
@@ -501,7 +504,10 @@ x is not None and ICMP in x and x[ICMP].type == 0
 ~ netaccess IP UDP DNS
 * A possible cause of failure could be that the open DNS (resolver1.opendns.com)
 * is not reachable or down.
+old_debug_dissector = conf.debug_dissector
+conf.debug_dissector = False
 dns_ans = sr1(IP(dst="resolver1.opendns.com")/UDP()/DNS(rd=1,qd=DNSQR(qname="www.slashdot.com")),timeout=5)
+conf.debug_dissector = old_debug_dissector
 DNS in dns_ans
 
 = Whois request
@@ -579,7 +585,10 @@ len(_) == 12
 
 = Port scan
 ~ netaccess IP TCP
+old_debug_dissector = conf.debug_dissector
+conf.debug_dissector = False
 ans,unans=sr(IP(dst="www.google.com/30")/TCP(dport=[80,443]),timeout=2)
+conf.debug_dissector = old_debug_dissector
 ans.make_table(lambda (s,r): (s.dst, s.dport, r.sprintf("{TCP:%TCP.flags%}{ICMP:%ICMP.code%}")))
 
 = Traceroute function
-- 
GitLab