From 578ba63ab115cfbc2374c6b7a4d1fae5fffd18ee Mon Sep 17 00:00:00 2001 From: Cyril Hrubis Date: Thu, 9 Jan 2025 16:03:36 +0100 Subject: [PATCH] safe_macros: Fix confusing safe_read() failure output 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 Signed-off-by: Cyril Hrubis Reviewed-by: Petr Vorel --- 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 10926858707..b224a586147 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;