diff options
author | 2011-03-05 22:10:11 +0000 | |
---|---|---|
committer | 2011-03-05 22:10:11 +0000 | |
commit | ebb4ed69e98da281c0adb4141a4d2f42eeae3ce8 (patch) | |
tree | 1715fbe8a4820d550e11151a9ca42083c8609544 /lib/libc/stdlib/getopt_long.c | |
parent | Fix potential crash when GZIP variable set and more than 512 command (diff) | |
download | wireguard-openbsd-ebb4ed69e98da281c0adb4141a4d2f42eeae3ce8.tar.xz wireguard-openbsd-ebb4ed69e98da281c0adb4141a4d2f42eeae3ce8.zip |
Fix PR 6267: recheck POSIXLY_CORRECT each time getopt_long() starts a new
argv and don't suppress the handling of leading '-' in optstring when
POSIXLY_CORRECT is set.
Based on patch from Eric Blake.
ok and manpage update from millert@, manpage ok jmc@
Diffstat (limited to 'lib/libc/stdlib/getopt_long.c')
-rw-r--r-- | lib/libc/stdlib/getopt_long.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/lib/libc/stdlib/getopt_long.c b/lib/libc/stdlib/getopt_long.c index eb1e3ef4be5..e149fe0ace2 100644 --- a/lib/libc/stdlib/getopt_long.c +++ b/lib/libc/stdlib/getopt_long.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getopt_long.c,v 1.24 2010/07/22 19:31:53 blambert Exp $ */ +/* $OpenBSD: getopt_long.c,v 1.25 2011/03/05 22:10:11 guenther Exp $ */ /* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */ /* @@ -285,25 +285,25 @@ getopt_internal(int nargc, char * const *nargv, const char *options, return (-1); /* + * XXX Some GNU programs (like cvs) set optind to 0 instead of + * XXX using optreset. Work around this braindamage. + */ + if (optind == 0) + optind = optreset = 1; + + /* * Disable GNU extensions if POSIXLY_CORRECT is set or options * string begins with a '+'. */ - if (posixly_correct == -1) + if (posixly_correct == -1 || optreset) posixly_correct = (getenv("POSIXLY_CORRECT") != NULL); - if (posixly_correct || *options == '+') - flags &= ~FLAG_PERMUTE; - else if (*options == '-') + if (*options == '-') flags |= FLAG_ALLARGS; + else if (posixly_correct || *options == '+') + flags &= ~FLAG_PERMUTE; if (*options == '+' || *options == '-') options++; - /* - * XXX Some GNU programs (like cvs) set optind to 0 instead of - * XXX using optreset. Work around this braindamage. - */ - if (optind == 0) - optind = optreset = 1; - optarg = NULL; if (optreset) nonopt_start = nonopt_end = -1; |