CVS commit: othersrc/external/bsd/getopt2/dist

2013-02-28 Thread Alistair G. Crooks
Module Name:othersrc
Committed By:   agc
Date:   Fri Mar  1 07:19:48 UTC 2013

Modified Files:
othersrc/external/bsd/getopt2/dist: getopt2.c

Log Message:
increment the sub-index if we're presented with an argument consisting of
single character options, and none is matched: as in "tar -cvzf ..."


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 othersrc/external/bsd/getopt2/dist/getopt2.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: othersrc/external/bsd/getopt2/dist/getopt2.c
diff -u othersrc/external/bsd/getopt2/dist/getopt2.c:1.2 othersrc/external/bsd/getopt2/dist/getopt2.c:1.3
--- othersrc/external/bsd/getopt2/dist/getopt2.c:1.2	Wed Nov 28 06:51:23 2012
+++ othersrc/external/bsd/getopt2/dist/getopt2.c	Fri Mar  1 07:19:47 2013
@@ -29,6 +29,19 @@
 
 #include "getopt2.h"
 
+static void
+increment_index(getopt2_t *options, char **argv, int subind)
+{
+	if (argv[options->optind][subind] == 0x0) {
+		options->optsubind = 0;
+		options->optind += 1;
+	} else {
+		options->optsubind = subind;
+	}
+}
+
+/***/
+
 int
 getopt2_init(getopt2_t *options)
 {
@@ -64,7 +77,9 @@ getopt2(getopt2_t *options, int argc, ch
 		return options->optopt = -1;
 	}
 	if ((opt = strchr(optstring, ch)) == NULL) {
+		/* option given is not one that's recognised */
 		(void) fprintf(stderr, "getopt2: '%c' unknown option\n", ch);
+		increment_index(options, argv, subind);
 		return options->optopt = '?';
 	}
 	switch(*(opt + 1)) {
@@ -94,12 +109,7 @@ getopt2(getopt2_t *options, int argc, ch
 		options->optsubind = 0;
 		break;
 	default:
-		if (argv[options->optind][subind] == 0x0) {
-			options->optsubind = 0;
-			options->optind += 1;
-		} else {
-			options->optsubind = subind;
-		}
+		increment_index(options, argv, subind);
 		options->optarg = NULL;
 		break;
 	}



CVS commit: othersrc/external/bsd/getopt2/dist

2012-11-27 Thread Alistair G. Crooks
Module Name:othersrc
Committed By:   agc
Date:   Wed Nov 28 06:51:24 UTC 2012

Modified Files:
othersrc/external/bsd/getopt2/dist: getopt2.c

Log Message:
more feedback from fuzz testing round:

check arguments passed to us, return error codes if they're not good.


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.1 -r1.2 othersrc/external/bsd/getopt2/dist/getopt2.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: othersrc/external/bsd/getopt2/dist/getopt2.c
diff -u othersrc/external/bsd/getopt2/dist/getopt2.c:1.1.1.1 othersrc/external/bsd/getopt2/dist/getopt2.c:1.2
--- othersrc/external/bsd/getopt2/dist/getopt2.c:1.1.1.1	Fri Jul 15 05:30:48 2011
+++ othersrc/external/bsd/getopt2/dist/getopt2.c	Wed Nov 28 06:51:23 2012
@@ -32,6 +32,9 @@
 int
 getopt2_init(getopt2_t *options)
 {
+	if (options == NULL) {
+		return 0;
+	}
 	(void) memset(options, 0x0, sizeof(*options));
 	options->optind = 1;
 	return 1;
@@ -44,6 +47,9 @@ getopt2(getopt2_t *options, int argc, ch
 	char		 ch;
 	int		 subind;
 
+	if (options == NULL || argc < 0 || argv == NULL || optstring == NULL) {
+		return -1;
+	}
 	if (options->optind == 0) {
 		/* allow for straight getopt2() invocation without init */
 		getopt2_init(options);