Use dynamic memory allocation instead of variable-length arrays

Since it is easy to trigger a stack overflow with variable-length arrays,
use dynamic memory allocation instead of VLAs. Add -Wvla to the compiler
options such that no new VLAs get introduced.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
This commit is contained in:
Bart Van Assche
2019-11-03 14:12:20 -08:00
parent 88f67e8cf8
commit 9d2493248b
9 changed files with 70 additions and 17 deletions

View File

@@ -329,8 +329,8 @@ static struct scsi_task *send_scsi_command(struct scsi_device *sdev, struct scsi
#ifdef HAVE_SG_IO
if (sdev->sgio_dev) {
sg_io_hdr_t io_hdr;
unsigned int sense_len=32;
unsigned char sense[sense_len];
unsigned char sense[32];
const unsigned int sense_len = sizeof(sense);
char buf[1024];
memset(sense, 0, sizeof(sense));