[PATCH v2] exec: make printable macro more concise
From: Nir Lichtman
Date: Sat Nov 16 2024 - 01:13:09 EST
Problem: The printable macro in exec.c uses custom logic
to determine if a character is printable, even though
the kernel supplies existing facilities.
Solution: Refactor to use isprint and isspace.
Signed-off-by: Nir Lichtman <nir@xxxxxxxxxxxx>
---
v2: fix to also consider space characters as printables
Side-note: I called the previous version "refactor an invalid
executable check to use isprint"
fs/exec.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/exec.c b/fs/exec.c
index 6c53920795c2..3b4c7548427f 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1723,7 +1723,7 @@ int remove_arg_zero(struct linux_binprm *bprm)
}
EXPORT_SYMBOL(remove_arg_zero);
-#define printable(c) (((c)=='\t') || ((c)=='\n') || (0x20<=(c) && (c)<=0x7e))
+#define printable(c) (isprint(c) || isspace(c))
/*
* cycle the list of binary formats handler, until one recognizes the image
*/
--
2.39.2