|
6 | 6 | * - we discard the valid Act 1 packet |
7 | 7 | * 2. initiator calls io_read() for the Act 2 packet |
8 | 8 | * - we inject the fuzzer-generated packet |
9 | | - * 3. initiator fails to validate the packet |
| 9 | + * 3. if packet is valid, initiator calls io_write() with an Act 3 packet |
| 10 | + * - we fail the handshake |
10 | 11 | */ |
11 | 12 | #include "config.h" |
12 | 13 | #include <assert.h> |
|
18 | 19 |
|
19 | 20 | /* The io_write() interceptor. |
20 | 21 | * |
21 | | - * This should be called exactly once, when the initiator is writing out its Act |
22 | | - * 1 packet. We check that the packet is initialized and discard it. */ |
| 22 | + * If the fuzzer-generated Act 2 packet was invalid, this should be called |
| 23 | + * exactly once, when the initiator is writing out its Act 1 packet. Otherwise, |
| 24 | + * if the Act 2 packet was valid, this should be called a second time, when the |
| 25 | + * initiator is writing out its Act 3 packet. */ |
23 | 26 | static struct io_plan * |
24 | 27 | test_write(struct io_conn *conn, const void *data, size_t len, |
25 | 28 | struct io_plan *(*next)(struct io_conn *, struct handshake *), |
26 | 29 | struct handshake *h) |
27 | 30 | { |
28 | 31 | ++write_count; |
29 | | - assert(write_count == 1 && "too many calls to io_write()"); |
| 32 | + if (write_count == 1) { |
| 33 | + /* Initiator is sending the Act 1 packet. Check that it is |
| 34 | + * initialized and discard it. */ |
| 35 | + assert(len == ACT_ONE_SIZE); |
| 36 | + memcheck(data, len); |
30 | 37 |
|
31 | | - assert(len == ACT_ONE_SIZE); |
| 38 | + return next(conn, h); |
| 39 | + } |
| 40 | + assert(write_count == 2 && "too many calls to io_write()"); |
| 41 | + |
| 42 | + /* Act 2 packet validation succeeded. Initiator is sending the Act 3 |
| 43 | + * packet. Check that it is initialized. */ |
| 44 | + assert(len == ACT_THREE_SIZE); |
32 | 45 | memcheck(data, len); |
33 | 46 |
|
34 | | - return next(conn, h); |
| 47 | + return handshake_failed(conn, h); |
35 | 48 | } |
36 | 49 |
|
37 | 50 | /* The io_read() interceptor. |
|
0 commit comments