All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] syscalls/acct02: Check read size.
@ 2019-09-25  9:47 Cyril Hrubis
  2019-09-25 13:56 ` Petr Vorel
  0 siblings, 1 reply; 15+ messages in thread
From: Cyril Hrubis @ 2019-09-25  9:47 UTC (permalink / raw)
  To: ltp

This is just a minor adjustements that checks that we get correct size
from read before we attempt to validate the data we read in order to
print more meaningful failure message.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/acct/acct02.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/syscalls/acct/acct02.c b/testcases/kernel/syscalls/acct/acct02.c
index 110d99359..bdb7c1194 100644
--- a/testcases/kernel/syscalls/acct/acct02.c
+++ b/testcases/kernel/syscalls/acct/acct02.c
@@ -171,10 +171,21 @@ static void run(void)
 	acct(NULL);
 
 	do {
-		tst_res(TINFO, "== entry %d ==", ++i);
-
 		read_bytes = SAFE_READ(0, fd, &acct_struct, acct_size);
 
+		if (i == 0 && read_bytes == 0) {
+			tst_res(TFAIL, "acct file is empty");
+			goto exit;
+		}
+
+		if (read_bytes != acct_size) {
+			tst_res(TFAIL, "incomplete read %i bytes, expected %i",
+			        read_bytes, acct_size);
+			goto exit;
+		}
+
+		tst_res(TINFO, "== entry %d ==", ++i);
+
 		if (v3)
 			ret = verify_acct(&acct_struct.v3, acct_struct.v3.ac_etime);
 		else
@@ -192,6 +203,7 @@ static void run(void)
 	else
 		tst_res(TPASS, "acct() wrote correct file contents!");
 
+exit:
 	SAFE_CLOSE(fd);
 }
 
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2019-11-01  8:54 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-25  9:47 [LTP] [PATCH] syscalls/acct02: Check read size Cyril Hrubis
2019-09-25 13:56 ` Petr Vorel
2019-09-25 16:14   ` Cyril Hrubis
2019-09-27 11:38   ` Cyril Hrubis
2019-09-27 12:48     ` Petr Vorel
2019-10-30  9:06   ` Jan Stancek
2019-10-30 13:03     ` Jan Stancek
2019-10-30 14:46       ` Petr Vorel
2019-10-30 17:41         ` Jan Stancek
2019-10-31  8:43           ` Li Wang
2019-10-31  8:53             ` Jan Stancek
2019-10-31  9:09               ` Petr Vorel
2019-11-01  6:03               ` Li Wang
2019-11-01  8:54                 ` Jan Stancek
2019-10-31  9:06           ` Petr Vorel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.