return 1;
}
+/*
+ * Prepend frame data into a packet. To be called from a packet_plain_listener
+ * callback
+ */
+int ossl_quic_fault_prepend_frame(OSSL_QUIC_FAULT *fault, unsigned char *frame,
+ size_t frame_len)
+{
+ unsigned char *buf;
+ size_t old_len;
+
+ /*
+ * Alloc'd size should always be non-zero, so if this fails we've been
+ * incorrectly called
+ */
+ if (fault->pplainbuf_alloc == 0)
+ return 0;
+
+ /* Cast below is safe because we allocated the buffer */
+ buf = (unsigned char *)fault->pplainio.buf;
+ old_len = fault->pplainio.buf_len;
+
+ /* Extend the size of the packet by the size of the new frame */
+ if (!TEST_true(ossl_quic_fault_resize_plain_packet(fault,
+ old_len + frame_len)))
+ return 0;
+
+ memmove(buf + frame_len, buf, old_len);
+ memcpy(buf, frame, frame_len);
+
+ return 1;
+}
+
static int handshake_mutate(const unsigned char *msgin, size_t msginlen,
unsigned char **msgout, size_t *msgoutlen,
void *arg)
ossl_quic_fault_on_packet_plain_cb pplaincb,
void *pplaincbarg);
+
/*
* Helper function to be called from a packet_plain_listener callback if it
* wants to resize the packet (either to add new data to it, or to truncate it).
*/
int ossl_quic_fault_resize_plain_packet(OSSL_QUIC_FAULT *fault, size_t newlen);
+/*
+ * Prepend frame data into a packet. To be called from a packet_plain_listener
+ * callback
+ */
+int ossl_quic_fault_prepend_frame(OSSL_QUIC_FAULT *fault, unsigned char *frame,
+ size_t frame_len);
+
/*
* The general handshake message listener is sent the entire handshake message
* data block, including the handshake header itself
static int add_unknown_frame_cb(OSSL_QUIC_FAULT *fault, QUIC_PKT_HDR *hdr,
unsigned char *buf, size_t len, void *cbarg)
{
- size_t done = 0;
-
+ static size_t done = 0;
/*
* There are no "reserved" frame types which are definitately safe for us
* to use for testing purposes - but we just use the highest possible
};
/* We only ever add the unknown frame to one packet */
- if (done)
+ if (done++)
return 1;
- done++;
-
- /* Extend the size of the packet by the size of the new frame */
- if (!TEST_true(ossl_quic_fault_resize_plain_packet(fault,
- len + sizeof(unknown_frame))))
- return 0;
- /*
- * We prepend the new frame to the start of the packet. We add it to the
- * start rather than the end because stream frames that are already in the
- * packet may not have an explicit length, and instead may just extend to
- * the end of the packet. We could fix-up such frames to have an explicit
- * length and add our new frame after it. But it is probably simpler just to
- * add it to the beginning of the packet. This means moving the existing
- * packet data.
- */
- memmove(buf + sizeof(unknown_frame), buf, len);
- memcpy(buf, unknown_frame, sizeof(unknown_frame));
-
- return 1;
+ return ossl_quic_fault_prepend_frame(fault, unknown_frame,
+ sizeof(unknown_frame));
}
static int test_unknown_frame(void)