From 8699d04ccc73ba481505226b9e6bfff85a93c34c Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 10 Aug 2024 19:00:32 -0600 Subject: [PATCH] str(1): updates to use pledge(2) --- src/str.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/str.c b/src/str.c index 9f7b351..35d19b1 100644 --- a/src/str.c +++ b/src/str.c @@ -22,7 +22,11 @@ #include /* fprintf(3) */ #include /* size_t, EXIT_FAILURE */ #include /* strcmp(3) */ -#include /* EX_USAGE */ +#include /* EX_OSERR, EX_USAGE */ + +#ifdef __OpenBSD__ +# include /* pledge(2) */ +#endif char *program_name = "str"; @@ -55,8 +59,16 @@ usage(char *argv0) { int main(int argc, char *argv[]) { size_t ctype; // selected from ctypes.h; index of ctype int retval; // initially fail but becomes success on the first valid char + program_name = argv[0] == NULL ? program_name : argv[0]; - if (argc < 3) { return usage(argv[0] == NULL ? program_name : argv[0]); } +#ifdef __OpenBSD__ + if (pledge("stdio", NULL) == -1) { + perror(program_name); + return EX_OSERR; + } +#endif + + if (argc < 3) { return usage(program_name); } for ( /* iterate ctypes */ ctype = 0;