From: Jian Yu Date: Thu, 20 Jan 2022 19:06:42 +0000 (-0800) Subject: LU-15220 tests: avoid gcc-11 -Werror=stringop-overread warning X-Git-Tag: 2.15.0-RC1~45 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=c5fb44f5ecf8494cd5a497947981bd6905ddc084;p=fs%2Flustre-release.git LU-15220 tests: avoid gcc-11 -Werror=stringop-overread warning GCC 11 warns about string and memory operations on fixed address: In function 'memcpy', inlined from 'obd_uuid2str' at lustre/include/uapi/linux/lustre/lustre_user.h:1222:3, include/linux/fortify-string.h:20:33: error: '__builtin_memcpy' reading 39 bytes from a region of size 0 [-Werror=stringop-overread] 20 | #define __underlying_memcpy __builtin_memcpy | ^ include/linux/fortify-string.h:191:16: note: in expansion of macro '__underlying_memcpy' 191 | return __underlying_memcpy(p, q, size); | ^~~~~~~~~~~~~~~~~~~ The patch avoids the above warning by not using a fixed address. badarea_io.c:47:14: error: 'write' reading 5 bytes from a region of size 0 [-Werror=stringop-overread] 47 | rc = write(fd, (void *)0x4096000, 5); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The patch avoids the above warning by making the pointer volatile as suggested in: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578#c16 Change-Id: I90b936835c6236a0f47e744013e3e480442f682c Signed-off-by: Jian Yu Reviewed-on: https://review.whamcloud.com/45777 Tested-by: jenkins Reviewed-by: Arshad Hussain Tested-by: Maloo Reviewed-by: Patrick Farrell Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- diff --git a/lustre/include/uapi/linux/lustre/lustre_user.h b/lustre/include/uapi/linux/lustre/lustre_user.h index 8f746ec..e9be1a6 100644 --- a/lustre/include/uapi/linux/lustre/lustre_user.h +++ b/lustre/include/uapi/linux/lustre/lustre_user.h @@ -1218,9 +1218,11 @@ static inline char *obd_uuid2str(const struct obd_uuid *uuid) if (uuid->uuid[sizeof(*uuid) - 1] != '\0') { /* Obviously not safe, but for printfs, no real harm done... we're always null-terminated, even in a race. */ - static char temp[sizeof(*uuid)]; - memcpy(temp, uuid->uuid, sizeof(*uuid) - 1); - temp[sizeof(*uuid) - 1] = '\0'; + static char temp[sizeof(*uuid->uuid)]; + + memcpy(temp, uuid->uuid, sizeof(*uuid->uuid) - 1); + temp[sizeof(*uuid->uuid) - 1] = '\0'; + return temp; } return (char *)(uuid->uuid); diff --git a/lustre/tests/badarea_io.c b/lustre/tests/badarea_io.c index e7395b2..a46b598 100644 --- a/lustre/tests/badarea_io.c +++ b/lustre/tests/badarea_io.c @@ -35,8 +35,11 @@ int main(int argc, char **argv) { int rc; - int fd = open(argv[1], O_WRONLY); + int fd; + void *volatile buf = (void *)0x4096000; + void *volatile fd_ptr; + fd = open(argv[1], O_WRONLY); if (fd == -1) { perror(argv[1]); goto read; @@ -44,27 +47,28 @@ int main(int argc, char **argv) /* We need rc because Sles11 compiler warns against unchecked * return value of read and write */ - rc = write(fd, (void *)0x4096000, 5); + rc = write(fd, buf, 5); if (rc != 5) perror("write badarea (Should have failed)"); - rc = write(fd, &fd, 0); + fd_ptr = (void *)&fd; + rc = write(fd, fd_ptr, 0); if (rc != 0) perror("write zero bytes"); - rc = write(fd, &fd, 1); + rc = write(fd, fd_ptr, 1); if (rc != 1) perror("write one byte"); - rc = write(fd, &fd, 2UL*1024*1024); + rc = write(fd, fd_ptr, 2UL*1024*1024); if (rc != 2UL*1024*1024) perror("write 2M"); - rc = write(fd, &fd, 2UL*1024*1024*1024); + rc = write(fd, fd_ptr, 2UL*1024*1024*1024); if (rc != 2UL*1024*1024*1024) perror("write 2G"); - rc = write(fd, &fd, -2); + rc = write(fd, fd_ptr, -2); if (rc != -2) perror("write -2"); @@ -74,7 +78,7 @@ read: fd = open(argv[1], O_RDONLY); if (fd == -1) return 0; - rc = read(fd, (void *)0x4096000, 5); + rc = read(fd, buf, 5); perror("read"); close(fd);