From e22c803cbdcdb6565b9d8bfd6a1a2407e92e6246 Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Tue, 16 Mar 2021 16:09:39 +0000 Subject: Check for overly large RVFI packets --- c_emulator/riscv_sim.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/c_emulator/riscv_sim.c b/c_emulator/riscv_sim.c index 71863cb..4fbeb07 100644 --- a/c_emulator/riscv_sim.c +++ b/c_emulator/riscv_sim.c @@ -683,6 +683,7 @@ static void get_and_send_rvfi_packet(packet_reader_fn *reader) { lbits packet; CREATE(lbits)(&packet); reader(&packet, UNIT); + /* Note: packet.len is the size in bits, not bytes. */ if (packet.len % 8 != 0) { fprintf(stderr, "RVFI-DII trace packet not byte aligned: %d\n", (int)packet.len); exit(1); @@ -692,6 +693,10 @@ static void get_and_send_rvfi_packet(packet_reader_fn *reader) { print_bits("packet = ", packet); fprintf(stderr, "Sending packet with length %zd... ", send_size); } + if (send_size > 4096) { + fprintf(stderr, "Unexpected large packet size (> 4KB): %zd\n", send_size); + exit(1); + } unsigned char bytes[send_size]; /* mpz_export might not write all of the null bytes */ memset(bytes, 0, sizeof(bytes)); -- cgit v1.1