From: Chun-Chen TK Hsu Date: Fri, 6 Sep 2019 11:42:56 +0000 (+0800) Subject: dev: Fix segmentation fault in VirtIOBlock X-Git-Tag: v19.0.0.0~580 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=665b67e365b11e791ff23b833d866d9ca4ffee77;p=gem5.git dev: Fix segmentation fault in VirtIOBlock GEM5 got a segmentation fault when the size is large in VirtIOBlock::write. This change uses a vector to avoid this segmentation fault. Signed-off-by: Chun-Chen TK Hsu Change-Id: I26272686a6e7e39cdf2389657ecd38ce90261144 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/20679 Reviewed-by: Andreas Sandberg Maintainer: Andreas Sandberg Tested-by: kokoro --- diff --git a/src/dev/virtio/block.cc b/src/dev/virtio/block.cc index a602c3e29..cf7f01bf6 100644 --- a/src/dev/virtio/block.cc +++ b/src/dev/virtio/block.cc @@ -71,7 +71,7 @@ VirtIOBlock::Status VirtIOBlock::read(const BlkRequest &req, VirtDescriptor *desc_chain, size_t off_data, size_t size) { - uint8_t data[size]; + std::vector data(size); uint64_t sector(req.sector); DPRINTF(VIOBlock, "Read request starting @ sector %i (size: %i)\n", @@ -81,14 +81,14 @@ VirtIOBlock::read(const BlkRequest &req, VirtDescriptor *desc_chain, panic("Unexpected request/sector size relationship\n"); for (Addr offset = 0; offset < size; offset += SectorSize) { - if (image.read(data + offset, sector) != SectorSize) { + if (image.read(&data[offset], sector) != SectorSize) { warn("Failed to read sector %i\n", sector); return S_IOERR; } ++sector; } - desc_chain->chainWrite(off_data, data, size); + desc_chain->chainWrite(off_data, &data[0], size); return S_OK; } @@ -97,7 +97,7 @@ VirtIOBlock::Status VirtIOBlock::write(const BlkRequest &req, VirtDescriptor *desc_chain, size_t off_data, size_t size) { - uint8_t data[size]; + std::vector data(size); uint64_t sector(req.sector); DPRINTF(VIOBlock, "Write request starting @ sector %i (size: %i)\n", @@ -107,10 +107,10 @@ VirtIOBlock::write(const BlkRequest &req, VirtDescriptor *desc_chain, panic("Unexpected request/sector size relationship\n"); - desc_chain->chainRead(off_data, data, size); + desc_chain->chainRead(off_data, &data[0], size); for (Addr offset = 0; offset < size; offset += SectorSize) { - if (image.write(data + offset, sector) != SectorSize) { + if (image.write(&data[offset], sector) != SectorSize) { warn("Failed to write sector %i\n", sector); return S_IOERR; }