From 34fcaee308bf494a04e7f5800f492e9726174c74 Mon Sep 17 00:00:00 2001 From: millert <> Date: Sun, 8 Dec 2002 17:52:26 +0000 Subject: [PATCH] SUS (and apparently 1003.1-2001) say to check optstring for NULL --- src/lib/libc/stdlib/getopt.c | 5 ++++- src/lib/libc/stdlib/getopt_long.c | 8 +++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/lib/libc/stdlib/getopt.c b/src/lib/libc/stdlib/getopt.c index b7f61636..218887dd 100644 --- a/src/lib/libc/stdlib/getopt.c +++ b/src/lib/libc/stdlib/getopt.c @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: getopt.c,v 1.2 1996/08/19 08:33:32 tholo Exp $"; +static char *rcsid = "$OpenBSD: getopt.c,v 1.3 2002/12/08 17:52:26 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -63,6 +63,9 @@ getopt(nargc, nargv, ostr) static char *place = EMSG; /* option letter processing */ char *oli; /* option letter list index */ + if (options == NULL) + return (-1); + if (optreset || !*place) { /* update scanning pointer */ optreset = 0; if (optind >= nargc || *(place = nargv[optind]) != '-') { diff --git a/src/lib/libc/stdlib/getopt_long.c b/src/lib/libc/stdlib/getopt_long.c index 176ba25b..413ec24f 100644 --- a/src/lib/libc/stdlib/getopt_long.c +++ b/src/lib/libc/stdlib/getopt_long.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getopt_long.c,v 1.9 2002/12/08 17:07:46 millert Exp $ */ +/* $OpenBSD: getopt_long.c,v 1.10 2002/12/08 17:52:26 millert Exp $ */ /* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */ /* @@ -64,7 +64,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: getopt_long.c,v 1.9 2002/12/08 17:07:46 millert Exp $"; +static char *rcsid = "$OpenBSD: getopt_long.c,v 1.10 2002/12/08 17:52:26 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -301,7 +301,8 @@ getopt_internal(int nargc, char * const *nargv, const char *options, int optchar, short_too; static int posixly_correct = -1; - optarg = NULL; + if (options == NULL) + return (-1); /* * Disable GNU extensions if POSIXLY_CORRECT is set or options @@ -323,6 +324,7 @@ getopt_internal(int nargc, char * const *nargv, const char *options, if (optind == 0) optind = optreset = 1; + optarg = NULL; if (optreset) nonopt_start = nonopt_end = -1; start: