[LTP] [PATCH 1/1] lib: Add missing checks for invalid return value
From: Petr Vorel <pvorel@suse.cz>
Date: 2024-07-11 20:13:34
Subsystem:
library code, the rest · Maintainers:
Andrew Morton, Linus Torvalds
It's a common approach to test invalid return value in safe macros. Signed-off-by: Petr Vorel <pvorel@suse.cz> --- include/lapi/landlock.h | 12 ++++++++++++ lib/tst_safe_macros.c | 4 ++++ 2 files changed, 16 insertions(+)
diff --git a/include/lapi/landlock.h b/include/lapi/landlock.h
index 6d85eb12e3..d3fa760e5b 100644
--- a/include/lapi/landlock.h
+++ b/include/lapi/landlock.h@@ -133,6 +133,10 @@ static inline int safe_landlock_create_ruleset(const char *file, const int linen tst_brk_(file, lineno, TBROK | TERRNO, "landlock_create_ruleset(%p, %lu, %u)", attr, size, flags); + } else if (rval < 0) { + tst_brk_(file, lineno, TBROK | TERRNO, + "Invalid landlock_create_ruleset(%p, %lu, %u) return value %d", + attr, size, flags, rval); } return rval;
@@ -151,6 +155,10 @@ static inline int safe_landlock_add_rule(const char *file, const int lineno, tst_brk_(file, lineno, TBROK | TERRNO, "landlock_add_rule(%d, %d, %p, %u)", ruleset_fd, rule_type, rule_attr, flags); + } else if (rval < 0) { + tst_brk_(file, lineno, TBROK | TERRNO, + "Invalid landlock_add_rule(%d, %d, %p, %u) return value %d", + ruleset_fd, rule_type, rule_attr, flags, rval); } return rval;
@@ -166,6 +174,10 @@ static inline int safe_landlock_restrict_self(const char *file, const int lineno tst_brk_(file, lineno, TBROK | TERRNO, "landlock_restrict_self(%d, %u)", ruleset_fd, flags); + } else if (rval < 0) { + tst_brk_(file, lineno, TBROK | TERRNO, + "Invalid landlock_restrict_self(%d, %u) return value %d", + ruleset_fd, flags, rval); } return rval;
diff --git a/lib/tst_safe_macros.c b/lib/tst_safe_macros.c
index 9301f3dd27..1bc5c92f58 100644
--- a/lib/tst_safe_macros.c
+++ b/lib/tst_safe_macros.c@@ -723,6 +723,10 @@ int safe_prctl(const char *file, const int lineno, tst_brk_(file, lineno, TBROK | TERRNO, "prctl(%d, %lu, %lu, %lu, %lu)", option, arg2, arg3, arg4, arg5); + } else if (rval < 0) { + tst_brk_(file, lineno, TBROK | TERRNO, + "Invalid prctl(%d, %lu, %lu, %lu, %lu) return value %d", + option, arg2, arg3, arg4, arg5, rval); } return rval;
--
2.45.2
--
Mailing list info: https://lists.linux.it/listinfo/ltp