From d0dd2684ce05940b53bb23928bc304e29f7b4a29 Mon Sep 17 00:00:00 2001 From: Takumi Ando Date: Wed, 15 Dec 2021 17:26:50 +0900 Subject: [PATCH] libc/unistd: getopt: Use argc to end parsing It should end parsing with argc even the argv are remaining or it may access to invalid address. Signed-off-by: Takumi Ando --- libs/libc/unistd/lib_getopt_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/libc/unistd/lib_getopt_common.c b/libs/libc/unistd/lib_getopt_common.c index c84d9a6550..be3e22a21a 100644 --- a/libs/libc/unistd/lib_getopt_common.c +++ b/libs/libc/unistd/lib_getopt_common.c @@ -393,7 +393,7 @@ int getopt_common(int argc, FAR char * const argv[], /* Check for the end of the argument list */ - go->go_optptr = argv[go->go_optind]; + go->go_optptr = go->go_optind < argc ? argv[go->go_optind] : NULL; if (!go->go_optptr) { /* There are no more arguments, we are finished */