[LTP] [PATCH 1/2] nfs01_open_files: Fix st_size check

Petr Vorel pvorel@suse.cz
Tue Mar 22 10:47:03 CET 2022


94c85d93e8 didn't update struct stat st_size check, but the problem was
hidden until dc836ec4cd (before code was not run).

Fixes: 94c85d93e8 ("nfs01: fix string overrrun")

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/network/nfs/nfs_stress/nfs01_open_files.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/testcases/network/nfs/nfs_stress/nfs01_open_files.c b/testcases/network/nfs/nfs_stress/nfs01_open_files.c
index cc6a84d685..0a4732859e 100644
--- a/testcases/network/nfs/nfs_stress/nfs01_open_files.c
+++ b/testcases/network/nfs/nfs_stress/nfs01_open_files.c
@@ -13,6 +13,8 @@
 #define TEMPLATE_PREFIX "ltp"
 #define TEMPLATE_PREFIX_LEN (sizeof(TEMPLATE_PREFIX) - 1)
 #define TEMPLATE TEMPLATE_PREFIX "XXXXXX"
+#define MSG "I Love Linux!!!\n"
+#define MSG_LEN (sizeof(MSG) - 1)
 
 int write_something(int);
 void delete_files(void);
@@ -84,7 +86,7 @@ int main(int argc, char *argv[])
 int write_something(int fd)
 {
 	int rc;
-	const char msg[] = "I Love Linux!!!\n";
+	const char msg[] = MSG;
 	int msg_len = strlen(msg);
 
 	rc = write(fd, msg, msg_len);
@@ -107,9 +109,11 @@ void delete_files(void)
 			if (stat(entp->d_name, &stat_buffer))
 				abortx("stat() failed for \"%s\", errno = %d",
 				       entp->d_name, errno);
-			if (stat_buffer.st_size != 23)
-				abortx("wrong file size for \"%s\"",
-				       entp->d_name);
+
+			if (stat_buffer.st_size != MSG_LEN)
+				abortx("wrong file size for \"%s\": %d",
+				       entp->d_name, stat_buffer.st_size);
+
 			if (unlink(entp->d_name))
 				abortx("unlink failed for \"%s\"",
 				       entp->d_name);
-- 
2.35.1



More information about the ltp mailing list