Module Name: src
Committed By: rin
Date: Tue Jul 2 05:26:40 UTC 2024
Modified Files:
src/sys/arch/prep/stand/boot: sd.c siop.c
Log Message:
prep: stand: Appease GCC12 -Warray-bounds, NFCI
except for additional 38-byte of stack being consumed.
Here, GCC12 complains buffer is smaller than
sizeof(*inqbuf) == SCSIPI_INQUIRY_LENGTH_SCSI3 == 74 bytes,
despite members within the first SCSIPI_INQUIRY_LENGTH_SCSI2 == 36 bytes
are actually dereferenced.
To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/prep/stand/boot/sd.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/prep/stand/boot/siop.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/prep/stand/boot/sd.c
diff -u src/sys/arch/prep/stand/boot/sd.c:1.4 src/sys/arch/prep/stand/boot/sd.c:1.5
--- src/sys/arch/prep/stand/boot/sd.c:1.4 Tue Jan 8 19:41:09 2019
+++ src/sys/arch/prep/stand/boot/sd.c Tue Jul 2 05:26:40 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: sd.c,v 1.4 2019/01/08 19:41:09 jdolecek Exp $ */
+/* $NetBSD: sd.c,v 1.5 2024/07/02 05:26:40 rin Exp $ */
/*
* Copyright (c) 2010 KIYOHARA Takashi
* All rights reserved.
@@ -568,10 +568,9 @@ sdopen(struct open_file *f, ...)
{
struct sd_softc *sd;
struct scsi_test_unit_ready cmd;
- struct scsipi_inquiry_data *inqbuf;
+ struct scsipi_inquiry_data buf, *inqbuf = &buf;
u_int bus, target, lun, part;
int error;
- char buf[SCSIPI_INQUIRY_LENGTH_SCSI2];
va_list ap;
va_start(ap, f);
@@ -594,11 +593,10 @@ sdopen(struct open_file *f, ...)
sd->sc_target = target;
sd->sc_bus = bus;
- if ((error = scsi_inquire(sd, sizeof(buf), buf)) != 0)
+ error = scsi_inquire(sd, SCSIPI_INQUIRY_LENGTH_SCSI2, inqbuf);
+ if (error != 0)
return error;
- inqbuf = (struct scsipi_inquiry_data *)buf;
-
sd->sc_type = inqbuf->device & SID_TYPE;
/*
Index: src/sys/arch/prep/stand/boot/siop.c
diff -u src/sys/arch/prep/stand/boot/siop.c:1.8 src/sys/arch/prep/stand/boot/siop.c:1.9
--- src/sys/arch/prep/stand/boot/siop.c:1.8 Thu Feb 8 19:44:08 2024
+++ src/sys/arch/prep/stand/boot/siop.c Tue Jul 2 05:26:40 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: siop.c,v 1.8 2024/02/08 19:44:08 andvar Exp $ */
+/* $NetBSD: siop.c,v 1.9 2024/07/02 05:26:40 rin Exp $ */
/*
* Copyright (c) 2010 KIYOHARA Takashi
* All rights reserved.
@@ -65,7 +65,7 @@ static void siop_xfer_setup(struct siop_
static int siop_add_reselsw(struct siop_adapter *, int, int);
static void siop_update_scntl3(struct siop_adapter *, int, int);
-static int _scsi_inquire(struct siop_adapter *, int, int, int, char *);
+static int _scsi_inquire(struct siop_adapter *, int, int, int, void *);
static void scsi_request_sense(struct siop_adapter *, struct scsi_xfer *);
static int scsi_interpret_sense(struct siop_adapter *, struct scsi_xfer *);
static int scsi_probe(struct siop_adapter *);
@@ -764,7 +764,7 @@ siop_update_scntl3(struct siop_adapter *
*/
static int
-_scsi_inquire(struct siop_adapter *adp, int t, int l, int buflen, char *buf)
+_scsi_inquire(struct siop_adapter *adp, int t, int l, int buflen, void *buf)
{
struct scsipi_inquiry *cmd = (struct scsipi_inquiry *)adp->cmd;
struct scsipi_inquiry_data *inqbuf =
@@ -1012,21 +1012,20 @@ scsi_interpret_sense(struct siop_adapter
static int
scsi_probe(struct siop_adapter *adp)
{
- struct scsipi_inquiry_data *inqbuf;
+ struct scsipi_inquiry_data buf, *inqbuf = &buf;
int found, t, l;
uint8_t device;
- char buf[SCSIPI_INQUIRY_LENGTH_SCSI2],
- product[sizeof(inqbuf->product) + 1];
+ char product[sizeof(inqbuf->product) + 1];
found = 0;
for (t = 0; t < 8; t++) {
if (t == adp->id)
continue;
for (l = 0; l < 8; l++) {
- if (_scsi_inquire(adp, t, l, sizeof(buf), buf) != 0)
+ if (_scsi_inquire(adp, t, l,
+ SCSIPI_INQUIRY_LENGTH_SCSI2, inqbuf) != 0)
continue;
- inqbuf = (struct scsipi_inquiry_data *)buf;
device = inqbuf->device & SID_TYPE;
if (device == T_NODEVICE)
continue;