int qtest_fault_delete_extension(QTEST_FAULT *fault,
unsigned int exttype, unsigned char *ext,
- size_t *extlen)
+ size_t *extlen,
+ BUF_MEM *old_ext)
{
PACKET pkt, sub, subext;
+ WPACKET old_ext_wpkt;
unsigned int type;
const unsigned char *start, *end;
- size_t newlen;
+ size_t newlen, w;
size_t msglen = fault->handbuflen;
if (!PACKET_buf_init(&pkt, ext, *extlen))
/* Found it */
end = PACKET_data(&sub);
+ if (old_ext != NULL) {
+ if (!WPACKET_init(&old_ext_wpkt, old_ext))
+ return 0;
+
+ if (!WPACKET_memcpy(&old_ext_wpkt, PACKET_data(&subext),
+ PACKET_remaining(&subext))
+ || !WPACKET_get_total_written(&old_ext_wpkt, &w)) {
+ WPACKET_cleanup(&old_ext_wpkt);
+ return 0;
+ }
+
+ WPACKET_finish(&old_ext_wpkt);
+ old_ext->length = w;
+ }
+
/*
* If we're not the last extension we need to move the rest earlier. The
* cast below is safe because we own the underlying buffer and we're no
* Helper function to delete an extension from an extension block. |exttype| is
* the type of the extension to be deleted. |ext| points to the extension block.
* On entry |*extlen| contains the length of the extension block. It is updated
- * with the new length on exit.
+ * with the new length on exit. If old_ext is non-NULL, the deleted extension
+ * is appended to the given BUF_MEM.
*/
int qtest_fault_delete_extension(QTEST_FAULT *fault,
unsigned int exttype, unsigned char *ext,
- size_t *extlen);
+ size_t *extlen,
+ BUF_MEM *old_ext);
/*
* Add additional helper functions for querying extensions here (e.g.
int *ext = (int *)encextcbarg;
if (!qtest_fault_delete_extension(fault, *ext, ee->extensions,
- &ee->extensionslen))
+ &ee->extensionslen, NULL))
return 0;
return 1;