Skip to content

Commit 869444a

Browse files
committed
safe_macros: Fix safe_write()
- Add return to the if (rval == -1) branch If we are in a cleanup the tst_brkm_() will return back and we will continue and print more tst_brkm_() messages particulary the "short write()" in the case of SAFE_WRITE_ALL - Add check for invalid return value (rval < 0) This will not happen unless there is a bug in libc but we should check for it anyways. - Remove TERRNO from the short write tst_brkm_() Since in a case of a short write the errno is not defined and we will print whatever was left there. Signed-off-by: Cyril Hrubis <chrubis@suse.cz> Reviewed-by: Petr Vorel <pvorel@suse.cz> Link: https://lore.kernel.org/ltp/20250109150336.25235-1-chrubis@suse.cz/
1 parent 578ba63 commit 869444a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/safe_macros.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,14 +551,22 @@ ssize_t safe_write(const char *file, const int lineno, void (cleanup_fn) (void),
551551
tst_brkm_(file, lineno, TBROK | TERRNO,
552552
cleanup_fn, "write(%d,%p,%zu) failed",
553553
fildes, buf, nbyte);
554+
return rval;
555+
}
556+
557+
if (rval < 0) {
558+
tst_brkm_(file, lineno, TBROK, cleanup_fn,
559+
"invalid write() return value %zi",
560+
rval);
561+
return rval;
554562
}
555563

556564
if (len_strict == SAFE_WRITE_ANY)
557565
return rval;
558566

559567
if (len_strict == SAFE_WRITE_ALL) {
560568
if ((size_t)rval != nbyte)
561-
tst_brkm_(file, lineno, TBROK | TERRNO,
569+
tst_brkm_(file, lineno, TBROK,
562570
cleanup_fn, "short write(%d,%p,%zu) "
563571
"return value %zd",
564572
fildes, buf, nbyte, rval);

0 commit comments

Comments
 (0)