diff --git a/ctaocrypt/src/asn.c b/ctaocrypt/src/asn.c index ccbb9e511..87ece4bf4 100644 --- a/ctaocrypt/src/asn.c +++ b/ctaocrypt/src/asn.c @@ -1102,6 +1102,8 @@ void InitDecodedCert(DecodedCert* cert, byte* source, word32 inSz, void* heap) void FreeAltNames(DNS_entry* altNames, void* heap) { + (void)heap; + while (altNames) { DNS_entry* tmp = altNames->next; diff --git a/cyassl/test.h b/cyassl/test.h index ddb4d04fb..bebe7478a 100644 --- a/cyassl/test.h +++ b/cyassl/test.h @@ -152,6 +152,74 @@ static INLINE void err_sys(const char* msg) } +#define MY_EX_USAGE 2 + +extern int myoptind; +extern char* myoptarg; + +static int mygetopt(int argc, char** argv, char* optstring) +{ + static char* next = NULL; + + char c; + char* cp; + + if (myoptind == 0) + next = NULL; /* we're starting new/over */ + + if (next == NULL || *next == '\0') { + if (myoptind == 0) + myoptind++; + + if (myoptind >= argc || argv[myoptind][0] != '-' || + argv[myoptind][1] == '\0') { + myoptarg = NULL; + if (myoptind < argc) + myoptarg = argv[myoptind]; + + return -1; + } + + if (strcmp(argv[myoptind], "--") == 0) { + myoptind++; + myoptarg = NULL; + + if (myoptind < argc) + myoptarg = argv[myoptind]; + + return -1; + } + + next = argv[myoptind]; + next++; /* skip - */ + myoptind++; + } + + c = *next++; + cp = strchr(optstring, c); + + if (cp == NULL || c == ':') + return '?'; + + cp++; + + if (*cp == ':') { + if (*next != '\0') { + myoptarg = next; + next = NULL; + } + else if (myoptind < argc) { + myoptarg = argv[myoptind]; + myoptind++; + } + else + return '?'; + } + + return c; +} + + #ifdef OPENSSL_EXTRA static int PasswordCallBack(char* passwd, int sz, int rw, void* userdata) diff --git a/examples/client/client.c b/examples/client/client.c index fc3c4e6ed..d9b49172b 100644 --- a/examples/client/client.c +++ b/examples/client/client.c @@ -25,7 +25,6 @@ #include #include -#include /* #define TEST_RESUME @@ -73,8 +72,8 @@ static void Usage(void) { - printf("client " VERSION " NOTE: All files relative to CyaSSL home dir" - "\n"); + printf("client " LIBCYASSL_VERSION_STRING + " NOTE: All files relative to CyaSSL home dir\n"); printf("-? Help, print this usage\n"); printf("-h Host to connect to, default %s\n", yasslIP); printf("-p Port to connect on, default %d\n", yasslPort); @@ -131,7 +130,7 @@ void client_test(void* args) ((func_args*)args)->return_code = -1; /* error state */ - while ((ch = getopt(argc, argv, "?gdsh:p:v:l:A:c:k:b:")) != -1) { + while ((ch = mygetopt(argc, argv, "?gdsh:p:v:l:A:c:k:b:")) != -1) { switch (ch) { case '?' : Usage(); @@ -150,54 +149,55 @@ void client_test(void* args) break; case 'h' : - host = optarg; - domain = optarg; + host = myoptarg; + domain = myoptarg; break; case 'p' : - port = atoi(optarg); + port = atoi(myoptarg); break; case 'v' : - version = atoi(optarg); + version = atoi(myoptarg); if (version < 0 || version > 3) { Usage(); - exit(EX_USAGE); + exit(MY_EX_USAGE); } break; case 'l' : - cipherList = optarg; + cipherList = myoptarg; break; case 'A' : - verifyCert = optarg; + verifyCert = myoptarg; break; case 'c' : - ourCert = optarg; + ourCert = myoptarg; break; case 'k' : - ourKey = optarg; + ourKey = myoptarg; break; case 'b' : - benchmark = atoi(optarg); + benchmark = atoi(myoptarg); if (benchmark < 0 || benchmark > 1000000) { Usage(); - exit(EX_USAGE); + exit(MY_EX_USAGE); } break; default: Usage(); - exit(EX_USAGE); + exit(MY_EX_USAGE); } } - argc -= optind; - argv += optind; + argc -= myoptind; + argv += myoptind; + myoptind = 0; /* reset for test cases */ switch (version) { case 0: @@ -442,6 +442,9 @@ void client_test(void* args) return args.return_code; } + int myoptind = 0; + char* myoptarg = NULL; + #endif /* NO_MAIN_DRIVER */ diff --git a/examples/server/server.c b/examples/server/server.c index a403b1878..8bf2e52db 100644 --- a/examples/server/server.c +++ b/examples/server/server.c @@ -25,7 +25,6 @@ #include #include -#include #ifdef CYASSL_CALLBACKS @@ -66,8 +65,8 @@ static void Usage(void) { - printf("server " VERSION " NOTE: All files relative to CyaSSL home dir" - "\n"); + printf("server " LIBCYASSL_VERSION_STRING + " NOTE: All files relative to CyaSSL home dir\n"); printf("-? Help, print this usage\n"); printf("-p Port to listen on, default %d\n", yasslPort); printf("-v SSL version [0-3], SSLv3(0) - TLS1.2(3)), default %d\n", @@ -109,7 +108,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args) ((func_args*)args)->return_code = -1; /* error state */ - while ((ch = getopt(argc, argv, "?dbsp:v:l:A:c:k:")) != -1) { + while ((ch = mygetopt(argc, argv, "?dbsp:v:l:A:c:k:")) != -1) { switch (ch) { case '?' : Usage(); @@ -128,41 +127,42 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args) break; case 'p' : - port = atoi(optarg); + port = atoi(myoptarg); break; case 'v' : - version = atoi(optarg); + version = atoi(myoptarg); if (version < 0 || version > 3) { Usage(); - exit(EX_USAGE); + exit(MY_EX_USAGE); } break; case 'l' : - cipherList = optarg; + cipherList = myoptarg; break; case 'A' : - verifyCert = optarg; + verifyCert = myoptarg; break; case 'c' : - ourCert = optarg; + ourCert = myoptarg; break; case 'k' : - ourKey = optarg; + ourKey = myoptarg; break; default: Usage(); - exit(EX_USAGE); + exit(MY_EX_USAGE); } } - argc -= optind; - argv += optind; + argc -= myoptind; + argv += myoptind; + myoptind = 0; /* reset for test cases */ switch (version) { case 0: @@ -319,6 +319,9 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args) return args.return_code; } + int myoptind = 0; + char* myoptarg = NULL; + #endif /* NO_MAIN_DRIVER */ diff --git a/testsuite/testsuite.c b/testsuite/testsuite.c index 0a64ee378..bc4b54448 100644 --- a/testsuite/testsuite.c +++ b/testsuite/testsuite.c @@ -48,6 +48,10 @@ enum { }; +int myoptind = 0; +char* myoptarg = NULL; + + int main(int argc, char** argv) { func_args args;