Currently test coverage is non-deterministic, which makes it hard to compare coverage between commits.
Fix one instance of non-determinism in net by adding an explicit test for this case:
0src/net.cpp: // if header incomplete, exit
Currently test coverage is non-deterministic, which makes it hard to compare coverage between commits.
Fix one instance of non-determinism in net by adding an explicit test for this case:
0src/net.cpp: // if header incomplete, exit
assert(false)
to the line that I claim to add coverage to and observing a deterministic crash when running the new test and no crash when running the previous test script.
106@@ -106,6 +107,20 @@ def test_large_inv(self):
107 conn.send_and_ping(msg)
108 self.nodes[0].disconnect_p2ps()
109
110+ def test_buffer(self):
111+ self.log.debug('Check that peer is disconnected for bad message even if some of the bytes are delayed')
info
.
117+ msg = b'\xff' * 4 + msg[4:]
118+ conn.send_raw_message(msg[:22])
119+ conn_ping.sync_with_ping()
120+ conn.send_raw_message(msg[22:])
121+ conn.wait_for_disconnect(timeout=1)
122+ self.nodes[0].disconnect_p2ps()
conn_ping
Interesting. I need to look at it more, but this seems to hit the conditional:
0--- a/src/net.cpp
1+++ b/src/net.cpp
2@@ -652,9 +652,10 @@ int V1TransportDeserializer::readHeader(const char *pch, unsigned int nBytes)
3 nHdrPos += nCopy;
4
5 // if header incomplete, exit
6- if (nHdrPos < CMessageHeader::HEADER_SIZE)
7+ if (nHdrPos < CMessageHeader::HEADER_SIZE) {
8+ LogPrintf("Incomplete header");
9 return nCopy;
10-
11+ }
12--- a/test/functional/p2p_invalid_messages.py
13+++ b/test/functional/p2p_invalid_messages.py
14 def test_buffer(self):
15 self.log.info('Check that peer is disconnected for bad message even if some of the bytes are delayed')
16 conn = self.nodes[0].add_p2p_connection(P2PDataStore())
17- conn_ping = self.nodes[0].add_p2p_connection(P2PDataStore())
18- with self.nodes[0].assert_debug_log(['PROCESSMESSAGE: INVALID MESSAGESTART badmsg']):
19+ with self.nodes[0].assert_debug_log(['Incomplete header', 'PROCESSMESSAGE: INVALID MESSAGESTART badmsg']):
20 msg = conn.build_message(msg_unrecognized(str_data="d"))
21 # modify magic bytes
22 msg = b'\xff' * 4 + msg[4:]
23 conn.send_raw_message(msg[:22])
24- conn_ping.sync_with_ping()
25 conn.send_raw_message(msg[22:])
26 conn.wait_for_disconnect(timeout=1)
27- self.nodes[0].disconnect_p2ps()
test_magic_bytes
; they could be placed next to each other.
they could be placed next to each other
Done
MarcoFalke
jonatack
jnewbery
troygiorshev
Labels
Tests