git: ee10c61d7a0a - main - stress2: Fix a off-by-one error. Added check for argument file type

From: Peter Holm <pho_at_FreeBSD.org>
Date: Mon, 06 Mar 2023 09:04:29 UTC
The branch main has been updated by pho:

URL: https://cgit.FreeBSD.org/src/commit/?id=ee10c61d7a0ae11a9d76c54a393587bd3933698e

commit ee10c61d7a0ae11a9d76c54a393587bd3933698e
Author:     Peter Holm <pho@FreeBSD.org>
AuthorDate: 2023-03-06 09:03:43 +0000
Commit:     Peter Holm <pho@FreeBSD.org>
CommitDate: 2023-03-06 09:03:43 +0000

    stress2: Fix a off-by-one error.  Added check for argument file type
---
 tools/test/stress2/tools/flip.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/test/stress2/tools/flip.c b/tools/test/stress2/tools/flip.c
index 8d01e9d78ea1..d73212c748bf 100644
--- a/tools/test/stress2/tools/flip.c
+++ b/tools/test/stress2/tools/flip.c
@@ -57,7 +57,7 @@ flip(void *ap, size_t len)
 	unsigned char bit, buf, mask, old __unused;
 
 	cp = (unsigned char *)ap;
-	byte = random_long(0, len);
+	byte = random_long(0, len - 1);
 	bit = random_long(0,7);
 	mask = ~(1 << bit);
 	buf = cp[byte];
@@ -111,6 +111,8 @@ main(int argc, char *argv[])
 	if (size == 0) {
 		if (fstat(fd, &st) == -1)
 			err(1, "stat %s", argv[0]);
+		if ((st.st_mode & S_IFREG) == 0)
+			errx(1, "%s must be a regular file\n", argv[0]);
 		size = st.st_size;
 	}