From 3520df21494727e5dcde19e079d06d8d9899c7f1 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Sat, 21 Nov 2020 10:59:13 +0100 Subject: [PATCH 01/17] Don't assume end of argv is NULL On a musl based system argv[optind] && strcmp(...) where optind > argc might read random memory and segfault. Signed-off-by: Erik Larsson --- lib/tpm2_options.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/tpm2_options.c b/lib/tpm2_options.c index e9aaa036..9fa583c6 100644 --- a/lib/tpm2_options.c +++ b/lib/tpm2_options.c @@ -300,7 +300,7 @@ tpm2_option_code tpm2_handle_options(int argc, char **argv, if (argv[optind - 1]) { if (!strcmp(argv[optind - 1], "--help=no-man") || !strcmp(argv[optind - 1], "-h=no-man") || - (argv[optind] && !strcmp(argv[optind], "no-man"))) { + (argc < optind && !strcmp(argv[optind], "no-man"))) { manpager = false; optind++; /* @@ -309,7 +309,7 @@ tpm2_option_code tpm2_handle_options(int argc, char **argv, */ } else if (!strcmp(argv[optind - 1], "--help=man") || !strcmp(argv[optind - 1], "-h=man") || - (argv[optind] && !strcmp(argv[optind], "man"))) { + (argc < optind && !strcmp(argv[optind], "man"))) { manpager = true; explicit_manpager = true; optind++; @@ -318,7 +318,7 @@ tpm2_option_code tpm2_handle_options(int argc, char **argv, * argv[0] = "tool name" * argv[1] = "--help" argv[2] = 0 */ - if (!argv[optind] && argc == 2) { + if (optind >= argc && argc == 2) { manpager = false; } else { /* -- 2.31.1