Fix free errors in ocsp utility.
authorDr. Stephen Henson <steve@openssl.org>
Wed, 9 Apr 2014 14:42:40 +0000 (15:42 +0100)
committerDr. Stephen Henson <steve@openssl.org>
Wed, 9 Apr 2014 14:42:40 +0000 (15:42 +0100)
Keep copy of any host, path and port values allocated by
OCSP_parse_url and free as necessary.

apps/ocsp.c

index ccf2f0f9497ae56e193240da4b5b0d3fc90d2d63..64c31826f3a97414e19ed13b102fd402dd01f9c3 100644 (file)
@@ -127,6 +127,7 @@ int MAIN(int argc, char **argv)
        ENGINE *e = NULL;
        char **args;
        char *host = NULL, *port = NULL, *path = "/";
        ENGINE *e = NULL;
        char **args;
        char *host = NULL, *port = NULL, *path = "/";
+       char *thost = NULL, *tport = NULL, *tpath = NULL;
        char *reqin = NULL, *respin = NULL;
        char *reqout = NULL, *respout = NULL;
        char *signfile = NULL, *keyfile = NULL;
        char *reqin = NULL, *respin = NULL;
        char *reqout = NULL, *respout = NULL;
        char *signfile = NULL, *keyfile = NULL;
@@ -206,6 +207,12 @@ int MAIN(int argc, char **argv)
                        }
                else if (!strcmp(*args, "-url"))
                        {
                        }
                else if (!strcmp(*args, "-url"))
                        {
+                       if (thost)
+                               OPENSSL_free(thost);
+                       if (tport)
+                               OPENSSL_free(tport);
+                       if (tpath)
+                               OPENSSL_free(tpath);
                        if (args[1])
                                {
                                args++;
                        if (args[1])
                                {
                                args++;
@@ -214,6 +221,9 @@ int MAIN(int argc, char **argv)
                                        BIO_printf(bio_err, "Error parsing URL\n");
                                        badarg = 1;
                                        }
                                        BIO_printf(bio_err, "Error parsing URL\n");
                                        badarg = 1;
                                        }
+                               thost = host;
+                               tport = port;
+                               tpath = path;
                                }
                        else badarg = 1;
                        }
                                }
                        else badarg = 1;
                        }
@@ -963,12 +973,12 @@ end:
        sk_X509_pop_free(verify_other, X509_free);
        sk_CONF_VALUE_pop_free(headers, X509V3_conf_free);
 
        sk_X509_pop_free(verify_other, X509_free);
        sk_CONF_VALUE_pop_free(headers, X509V3_conf_free);
 
-       if (use_ssl != -1)
-               {
-               OPENSSL_free(host);
-               OPENSSL_free(port);
-               OPENSSL_free(path);
-               }
+       if (thost)
+               OPENSSL_free(thost);
+       if (tport)
+               OPENSSL_free(tport);
+       if (tpath)
+               OPENSSL_free(tpath);
 
        OPENSSL_EXIT(ret);
 }
 
        OPENSSL_EXIT(ret);
 }