From 708abbf380e9745a67735f8b928d4a7a13dd24c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20Hor=C3=A1k?= Date: Mon, 6 Jun 2022 13:52:22 +0000 Subject: [PATCH] dasdfmt: fix buffer overread warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit dasdfmt.c: In function ‘dasdfmt_write_labels’: dasdfmt.c:1110:22: warning: ‘write’ reading 88 bytes from a region of size 4 [-Wstringop-overread] 1110 | rc = write(fd, &vlabel->vollbl, (sizeof(*vlabel) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1111 | - sizeof(vlabel->volkey))); | ~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from dasdfmt.c:23: ../include/lib/vtoc.h:84:14: note: source object ‘vollbl’ of size 4 84 | char vollbl[4]; /* volume label */ | ^~~~~~ In file included from ../include/lib/util_opt.h:16, from dasdfmt.c:20: /usr/include/unistd.h:378:16: note: in a call to function ‘write’ declared with attribute ‘access (read_only, 2, 3)’ 378 | extern ssize_t write (int __fd, const void *__buf, size_t __n) __wur | ^~~~~ GitHub-ID: https://github.com/ibm-s390-linux/s390-tools/pull/137 Signed-off-by: Dan Horák Acked-by: Jan Höppner Signed-off-by: Jan Höppner --- dasdfmt/dasdfmt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dasdfmt/dasdfmt.c b/dasdfmt/dasdfmt.c index 5665f649..fa25c03e 100644 --- a/dasdfmt/dasdfmt.c +++ b/dasdfmt/dasdfmt.c @@ -1107,8 +1107,8 @@ static void dasdfmt_write_labels(volume_label_t *vlabel, } else { vlabel->ldl_version = 0xf2; /* EBCDIC '2' */ vlabel->formatted_blocks = cylinders * heads * geo.sectors; - rc = write(fd, &vlabel->vollbl, (sizeof(*vlabel) - - sizeof(vlabel->volkey))); + rc = write(fd, (void *)vlabel + sizeof(vlabel->volkey), + (sizeof(*vlabel) - sizeof(vlabel->volkey))); } if (((rc != sizeof(*vlabel) - sizeof(vlabel->formatted_blocks)) &&