test/x509aux.c: Fix argv loop
authorRichard Levitte <levitte@openssl.org>
Wed, 21 Sep 2016 12:44:42 +0000 (14:44 +0200)
committerRichard Levitte <levitte@openssl.org>
Wed, 21 Sep 2016 14:19:22 +0000 (16:19 +0200)
There are cases when argc is more trustable than proper argv termination.
Since we trust argc in all other test programs, we might as well treat it
the same way in this program.

Reviewed-by: Matt Caswell <matt@openssl.org>
test/x509aux.c

index 4f00196312b089069121482a89fc761cfd911ef3..2c20d6d743355b6eab4f16afaea668e2e9d83abe 100644 (file)
@@ -180,7 +180,6 @@ static int test_certs(BIO *fp)
 int main(int argc, char *argv[])
 {
     BIO *bio_err;
 int main(int argc, char *argv[])
 {
     BIO *bio_err;
-    const char *certfile;
     const char *p;
     int ret = 1;
 
     const char *p;
     int ret = 1;
 
@@ -197,24 +196,30 @@ int main(int argc, char *argv[])
         CRYPTO_set_mem_debug(1);
     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
 
         CRYPTO_set_mem_debug(1);
     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
 
-    while ((certfile = *++argv) != NULL) {
-        BIO *f = BIO_new_file(certfile, "r");
+    argc--;
+    argv++;
+
+    while (argc >= 1) {
+        BIO *f = BIO_new_file(*argv, "r");
         int ok;
 
         if (f == NULL) {
             fprintf(stderr, "%s: Error opening cert file: '%s': %s\n",
         int ok;
 
         if (f == NULL) {
             fprintf(stderr, "%s: Error opening cert file: '%s': %s\n",
-                    progname, certfile, strerror(errno));
+                    progname, *argv, strerror(errno));
             EXIT(ret);
         }
         ret = !(ok = test_certs(f));
         BIO_free(f);
 
         if (!ok) {
             EXIT(ret);
         }
         ret = !(ok = test_certs(f));
         BIO_free(f);
 
         if (!ok) {
-            printf("%s ERROR\n", certfile);
+            printf("%s ERROR\n", *argv);
             ret = 1;
             break;
         }
             ret = 1;
             break;
         }
-        printf("%s OK\n", certfile);
+        printf("%s OK\n", *argv);
+
+        argc--;
+        argv++;
     }
 
 #ifndef OPENSSL_NO_CRYPTO_MDEBUG
     }
 
 #ifndef OPENSSL_NO_CRYPTO_MDEBUG