git: b03311cadd3a - main - renice: Avoid segfault if -n flag is given without argument.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 17 Apr 2023 19:51:13 UTC
The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=b03311cadd3a6f931e176f97b97bd72be3ef96d4 commit b03311cadd3a6f931e176f97b97bd72be3ef96d4 Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2023-04-17 19:49:13 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2023-04-17 19:50:19 +0000 renice: Avoid segfault if -n flag is given without argument. Fixes: 65ee0a8495538 MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D39623 --- usr.bin/renice/renice.c | 2 +- usr.bin/renice/tests/renice_test.sh | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/usr.bin/renice/renice.c b/usr.bin/renice/renice.c index 890d7043ebbd..42e93cce240e 100644 --- a/usr.bin/renice/renice.c +++ b/usr.bin/renice/renice.c @@ -94,7 +94,7 @@ main(int argc, char *argv[]) } if (strcmp(*argv, "-n") == 0) { /* may occur only once, prior to priority */ - if (haveprio || incr) + if (haveprio || incr || argc < 2) usage(); incr = true; (void)argc--, argv++; diff --git a/usr.bin/renice/tests/renice_test.sh b/usr.bin/renice/tests/renice_test.sh index 9321e0f327ae..a6e8007ba35d 100644 --- a/usr.bin/renice/tests/renice_test.sh +++ b/usr.bin/renice/tests/renice_test.sh @@ -158,6 +158,11 @@ renice_delim_body() { kill $pid } +atf_test_case renice_incr_noarg +renice_incr_noarg_body() { + atf_check -o empty -e ignore -s exit:1 renice -n +} + atf_init_test_cases() { atf_add_test_case renice_abs_pid atf_add_test_case renice_rel_pid @@ -166,4 +171,5 @@ atf_init_test_cases() { atf_add_test_case renice_abs_user atf_add_test_case renice_rel_user atf_add_test_case renice_delim + atf_add_test_case renice_incr_noarg }