public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] safe_macros: Fix confusing safe_read() failure output
@ 2025-01-09 15:03 Cyril Hrubis
  2025-01-09 16:18 ` Petr Vorel
  0 siblings, 1 reply; 5+ messages in thread
From: Cyril Hrubis @ 2025-01-09 15:03 UTC (permalink / raw)
  To: ltp

In the case that we read() less bytes than expected in the strict mode
we used the same tst_brk() as for the case when read() fails. However
for short reads the errno is in an udefined state and we possibly end up
with confusing TBROK message. Andrea reported EACESS ernno in the TBROK
message on a short read() while developing tests.

Reported-by: Andrea Cervesato <andrea.cervesato@suse.com>
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 lib/safe_macros.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/safe_macros.c b/lib/safe_macros.c
index 109268587..b224a5861 100644
--- a/lib/safe_macros.c
+++ b/lib/safe_macros.c
@@ -293,7 +293,7 @@ ssize_t safe_read(const char *file, const int lineno, void (*cleanup_fn) (void),
 
 	rval = read(fildes, buf, nbyte);
 
-	if (rval == -1 || (len_strict && (size_t)rval != nbyte)) {
+	if (rval == -1) {
 		tst_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
 			"read(%d,%p,%zu) failed, returned %zd", fildes, buf,
 			nbyte, rval);
@@ -301,6 +301,10 @@ ssize_t safe_read(const char *file, const int lineno, void (*cleanup_fn) (void),
 		tst_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
 			"Invalid read(%d,%p,%zu) return value %zd", fildes,
 			buf, nbyte, rval);
+	} else if (len_strict && (size_t)rval != nbyte) {
+		tst_brkm_(file, lineno, TBROK, cleanup_fn,
+			  "Short read(%d,%p,%zu) returned only %zd",
+			  fildes, buf, nbyte, rval);
 	}
 
 	return rval;
-- 
2.45.2


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

end of thread, other threads:[~2025-01-16 12:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-09 15:03 [LTP] [PATCH] safe_macros: Fix confusing safe_read() failure output Cyril Hrubis
2025-01-09 16:18 ` Petr Vorel
2025-01-16 11:15   ` Cyril Hrubis
2025-01-16 11:19     ` Petr Vorel
2025-01-16 12:01       ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox