From 98240d99f01edb9f211af4dfb5da53ea0d3b81e5 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Sun, 14 Jan 2007 02:01:26 +0000 Subject: [PATCH] Do not go past the end of the argv[] array. This bug found by setting read and write watchpoints at NULL in bochs. --- src/core/getopt.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/getopt.c b/src/core/getopt.c index 4e839cab..547aa694 100644 --- a/src/core/getopt.c +++ b/src/core/getopt.c @@ -227,6 +227,10 @@ int getopt_long ( int argc, char * const argv[], const char *optstring, enum getopt_argument_requirement has_arg; int option; + /* Check for end of argv array */ + if ( optind >= argc ) + return -1; + /* Check for end of options */ if ( *(opttext++) != '-' ) return -1;